Page 1 of 1

Images become blurry on downscale since I updated to v7

Posted: 2017-06-26T06:37:09-07:00
by Trost
My hosting provider decided to update software on their servers, and this had side-effects for me :(
They updated Imagick and\or ImageMagick and now, the function "resizeImage()", which used to work perfectly, returns a blurry result on downscale.
I still have accounts on same hosting that is on old server with old Imagick. I use the same line:

Code: Select all

$image->resizeImage(133, 200, Imagick::FILTER_CUBIC, 0.5);
On old server it returns a good image. On new one it returns a blurry mess.
Image
The old server has ImageMagick 6.9.4-0 Q16 x86_64 2016-05-09
The new (problematic) server uses ImageMagick 7.0.5-4 Q16 x86_64 2017-04-12
I've reported this as issue to ImageMagick GitHub (https://github.com/ImageMagick/ImageMag ... -310741602), but one of their developers tested it for me, and said that it's not a problem with ImageMagick, but a problem with this IMagick interface most likely.

I'm willing to provide additional information, as I really need to get my non-blurry image generation ASAP and my hosting provider doesn't want to roll back the server update...

UPD:
Servers with this bug also have imagick: 3.4.3, while old ones have imagick: 3.1.2
So that means that imagick: 3.4.3 + ImageMagick 7.0.5-4 Q16 x86_64 2017-04-12 results in blurry images on downscale...

Re: Images become blurry on downscale since I updated to v7

Posted: 2017-06-26T07:44:14-07:00
by snibgo
I downloaded your image, renamed it bluetop.jpg, and tried the following on IM v6.9.5-3 (on Windows 8.1):

Code: Select all

convert bluetop.jpg -resize "133x200^!" x.png

convert bluetop.jpg -filter cubic -resize "133x200^!" c.png
("!" gives an exact resize, instead of maintaining the aspect ratio.)

x.png is much sharper than c.png. c.png is mushy.

They look very much like your v6 and v7 results, respectively.

I'm not an expert at filters etc. Why are you using "-filter cubic"?

I conclude that your v7 version (or, more likely, IMagick) is respecting "-filter cubic", so you get the mushy result. Your v6 version ignores "-filter cubic" and uses the default filter, with the better result.

I suggest you omit "cubic". Does that look better?

Re: Images become blurry on downscale since I updated to v7

Posted: 2017-06-26T08:47:32-07:00
by Trost
snibgo wrote: 2017-06-26T07:44:14-07:00 I'm not an expert at filters etc. Why are you using "-filter cubic"?

I conclude that your v7 version (or, more likely, IMagick) is respecting "-filter cubic", so you get the mushy result. Your v6 version ignores "-filter cubic" and uses the default filter, with the better result.

I suggest you omit "cubic". Does that look better?
It's not like I chose to use -filter cubic. I use a CMS for an online shop, and that line of code is basically copy-pasted from the engine.
No idea why the developers of CMS chose to go with cubic filter, but it sure gave me a few days of headache to pinpoint the real cause of this blur.
Thank you so much! I changed it to

Code: Select all

$image->resizeImage(133, 200, 0, 0.5);
and it looks great now!

One more question - is inserting 0 instead of filter name the right way to omit it?

Re: Images become blurry on downscale since I updated to v7

Posted: 2017-06-26T09:51:49-07:00
by snibgo
Sorry, I don't use IMagick so I don't know, but from http://php.net/manual/en/imagick.resizeimage.php and http://php.net/manual/en/imagick.consta ... ts.filters , "FILTER_UNDEFINED" may be what you want (and this constant may be zero, of course).

"Cubic" was pretty much state of the art about 20 years ago, so the code you see may have descended from those times.

Re: Images become blurry on downscale since I updated to v7

Posted: 2017-06-26T09:56:41-07:00
by fmw42
Cubic is a broad range of filters defined by constants b,c. See http://www.imagemagick.org/Usage/filter/#cubics. I believe b is the blurring constant. So using b=0.5 may be adding too much blur. What is called (Keys) cubic convolution (the old standard) is what ImageMagick calls filter=catrom. It produces sharp results at the expense of other artifacts. Lanczos is another good filter which IM uses as default it many cases.

Re: Images become blurry on downscale since I updated to v7

Posted: 2017-06-26T10:24:39-07:00
by snibgo
fmw42 wrote:What is called cubic convolution ...
Ah, thanks, that's probably what I was trying to dig out of my rusty memory.

Re: Images become blurry on downscale since I updated to v7

Posted: 2017-06-27T02:39:25-07:00
by Trost
Looking here I can see that FILTER_CUBIC always results in a blurry output.
http://urmaul.com/blog/imagick-filters-comparison/
And changing the fourth parameter (blur factor) of resizeImage doesn't affect results in any way for me.
Anyways, I just used FILTER_UNDEFINED and this solved my problem.