Page MenuHomePhabricator

New thumbnails are not sharp
Closed, ResolvedPublic


Previously, whenever thumbnails were generated by ImageMagick, the sharpen option was used. This was especially helpful for small thumbnails of detailed images. It appears that this option may have recently been turned off judging by the softness of newly generated thumbnails.

New thumbnail (soft):

219px-Russian_Empire-Full_coat_of_arms.3.jpg (310×219 px, 28 KB)

Cached old thumbnail (sharp):

220px-Russian_Empire-Full_coat_of_arms.3.jpg (312×220 px, 34 KB)

This seems to have changed around the time of the recent ImageMagick update.

Version: unspecified
Severity: minor



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:01 PM
bzimport set Reference to bz24857.

Perhaps syntax change in imagemagick commandline ?

The correct current syntax is using the -unsharp option after the -thumbnail option. I think previously we were using a radius of 0.8 or something like that, so:
convert original.jpg -thumbnail 250x90 -unsharp 0.8 thumbnail.jpg

I have no idea if this is different than older syntaxes or what syntax we're using currently.

Ah, looks like the old syntax was -sharpen (which is a much more logical name). Apparently they're using an unsharp masking algorithm to do the sharpening now, so they decided they had to change the option name while they were at it!

I've fixed it in r71304.

Nevermind, we should be able to use -sharpen or -unsharp and they both should accept the parameter we're using (0x0.4). Hmm, back to the drawing board.

Maybe someone with command line access to our ImageMagick could do some tests and find out what's going on with it, i.e. test using 'convert -thumbnail' with -sharpen on and off, and then test it with -unsharp on and off, and see if there are any differences in the output files.

The issue is an arbitrary change in SharpenImageChannel() made some time between ImageMagick 6.4.9 and 6.5.1. The relevant code changed from this:

alpha=exp(-((double) u*u+v*v)/(2.0*MagickSigma*MagickSigma));
kernel[i]=(double) (-alpha/(2.0*MagickPI*MagickSigma*MagickSigma));
if ((width < 3) || (u != 0) || (v != 0))

To this:

alpha=exp(-((double) u*u+v*v)/(2.0*MagickSigma*MagickSigma));
kernel[i]=(double) (-alpha/(2.0*MagickPI*MagickSigma*MagickSigma));

The result is that for a given sigma, images look more blurry in the new convert. Based on brief testing, to reproduce a result similar to the old 0x0.4 requires a sharpen parameter of approximately 0x0.8 in the new ImageMagick.

Both -unsharp and -sharpen exist in both versions, and have completely different implementations. Unsharp does not appear to have changed significantly, so it might be a candidate for version-independent operation in the next MediaWiki release. But for now I will just change our configuration to use 0x0.8 instead of 0x0.4.

matmarex set Security to None.
Restricted Application added a subscriber: Matanya. · View Herald Transcript