Skip to main content
Topic: Image preview (Read 915 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Image preview

Not sure if this is a bug, but it's sure strange.

I inserted two attachments, one jpg and one in webp format, then I choose to insert those images inline with 200 px widh. Then I use the preview button and here is what I get:

Elkarte 1.1.9:
- the preview for jpg is in low quality
- the preview for the webp is in good quality

Elkarte 2.0
- both images in preview mode are in low quality

Like I said, not sure if it's a bug and how it was supposed to work the preview, strange is that on Elkarte 1.1.9 the webp image in preview mode is displayed in a good quality. I attach the images I used and the preview I see in both versions.

Re: Image preview

Reply #1

Yeah ... Humm

I was only seeing the low quality image but I'm using imagick in testing, so maybe GD is different (1.1.9). 

The issue stems from those tmp files we use when in preview, they were originally intended for use in the upload area, so they are just 100px thumbnails. When they get ila'ed in preview above 100px they look horrible!

A quick fix to try is in Attachment.controller.php
Code: (find) [Select]
		if ($resize && resizeImageFile($filename, $filename . '_thumb', 100, 100, $format))
Code: (replace) [Select]
		if ($resize && resizeImageFile($filename, $filename . '_thumb', 250, 250, $format, false, false))

That will provide a larger thumbnail image for use while still remaining a very small file so things do not slow down.   Give that a test and let me know, I'm testing it as well.

Re: Image preview

Reply #2

The above seems to work in my testing, however it allows the plain thumbnail size in the preview to  grow to large.  So the full fix will be

Code: (find) [Select]
		$format = setDefaultFormat($filename);
if ($resize && resizeImageFile($filename, $filename . '_thumb', 100, 100, $format))

Code: (replace) [Select]
		$max_width = $this->_req->is_set('thumb') && !empty($modSettings['attachmentThumbWidth']) ? $modSettings['attachmentThumbWidth'] : 250;
$max_height = $this->_req->is_set('thumb') && !empty($modSettings['attachmentThumbHeight']) ? $modSettings['attachmentThumbHeight'] : 250;
$format = setDefaultFormat($filename);
if ($resize && resizeImageFile($filename, $filename . '_thumb', $max_width, $max_height, $format, false, false))
Last Edit: December 03, 2022, 12:12:43 pm by Spuds

Re: Image preview

Reply #3

@radu81 did you have a chance to try the above fix on 1.1.9?

Re: Image preview

Reply #4

sorry for the delay, I just did and here is what I get:
Screenshot 2022-12-15 at 01-07-09.png

I am using PHP 7.4 and Imagick, I will send you by PM my setup configutation
sorry for my bad english

Re: Image preview

Reply #5

So I think we have a couple of items here.

First, what you show for the jpg image is correct (the fix is doing what it should) ... Notice that it looks much better than what you originally posted (for the jpg).  It has some blur, this is because we limit the resize in preview to 250x250px (could be set larger, maybe change the 250 to 300 in the above code)  Anyway, in this case the waterfall image returned to the UI is 188x250px then its asked to be shown in a 300px preview which is applied to the width and you end up with a 300x399 preview of a 188x250 image (aka some blur)

Second, why is the webp image not showing any blur you ask??  I think that is because the iMagick webp thumbnail fails on your server, so the image returned to the UI has not been resized.  The code silently catches the resize failure and continues on its way.  We need to figure out why your system fails, so please do the following:

in Graphics.subs.php
Code: (find) [Select]
		catch (Exception $e)
{
$success = false;
}
Code: (replace) [Select]
		catch (Exception $e)
{
Errors::instance()->log_error('Thumbnail error (' . $e->getMessage() . ')', 'critical');

$success = false;
}

If the resize is failing, this will log an error in the admin error log under the critical tab.  So please add that and test again and hopefully we see an error that we can address.  Maybe we should consider logging the error by default as well.
Last Edit: December 22, 2022, 05:54:33 am by radu81

Re: Image preview

Reply #6

@radu81 Were you able to make this edit on 1.1.9 and did it show any error in the log?

Re: Image preview

Reply #7

:embarrassed: I still have this topic marked as unread, sorry Spuds, I'll let you know as soon as I can  :embarrassed:
It's a messy period for me
sorry for my bad english

Re: Image preview

Reply #8

Thanks ... just wanted to make sure you saw the post:santa: