Page 1 of 1

How to improve image quality of thumbnails

Posted: Fri Sep 12, 2008 12:12 am
by konus
I was always not very happy with the image quality of the generated thumbnails. Thats why I stepped deeper into it and found a way to fix it. I would like to share with you my thoughts about it.

First of all, it is important to get imagemagick running, because it offers much more options to enhance images than gd-lib.

After I did this, I searched and found the pice of code, which does the resizing job. It is located at /include/functions_images.inc.php at around line 663

Code: Select all

$cmd     = escapeshellcmd($serendipity['convert']) . ' -antialias -resize '. serendipity_escapeshellarg($newSize) .' '. serendipity_escapeshellarg($infile) .' '. serendipity_escapeshellarg($outfile);
it is possible to add several options, which are described at the official website

I wanted to push up
brightness, saturation (with -modulate 105% and 150%), sharpness (by using a -unsharp-mask. The amount of sharpness is adjusted with the third parameter +1.0, leave the other two alone for output on screens. Very noisy images could use a 4th parameter called +threshold) and wanted to reduce
thumbnail-size (by using the option -quality).

It is recommended to do the sharpening at the end of image processing and thats why I inserted the sharpening in the end of the command line.
It results in the following code

Code: Select all

$cmd     = escapeshellcmd($serendipity['convert']) . ' -antialias -resize '. serendipity_escapeshellarg($newSize) .' -modulate 105,140 -unsharp 0.5x0.5+1.0 -quality 75 '. serendipity_escapeshellarg($infile) .' '. serendipity_escapeshellarg($outfile);
There is also the possibility to enhance -contrast and much more, just read the documentation.

So I hope it helps you. I would like to suggest to the developers to add sharpenig with a unsharp mask as standard procedure in the offical code. A other option would be, to allow useres to add some extra command line parameters in the configuration an pass them to the resize command.

Side note: A good explanation of the parameters of the option -unsharp could be find here

Posted: Fri Sep 12, 2008 2:46 am
by Don Chambers
I want Garvin to respond regarding code modifications, but I will add my support for the concept of unsharp mask for images that have been reduced in size.... that is always part of my workflow when I reduce images using photoshop. If there is a universal way to do that, then it has my support.

But understand that imagemagick is not always available and it may have implementation issues if it is exclusively available to imagemagick.

So, now I bow out and leave any potential code changes to Garvin or others who have greater experience with these matters! :wink:

Posted: Fri Sep 12, 2008 12:59 pm
by garvinhicking
Hi!

I think the best way to go with this would be to add a custom commmand line option set, however that has tough security restrictions that I don't know how to best handle, because we cannot simply pass through raw shell code from the user.

An option would be to only specify that option through serendipity_config_local.inc.php, because when someone can edit files, he can also create his own PHP commands. This however makes it complicated for users to add their own options.

A third option would be to enhance the imageselectorplus plugin to support specific options like "use sharpening", "use contrast" etc., but codewise that's the most complicated way.

Adding unsharp by default sounds good to me, but there are so many imagemagick versions out there. Does anyone know if unsharp is available on every version that are currently supported? If unsharp only is supported for imagemagick 8, this would be bad because many users still use 6.x or so...

HTH,
Garvin