Question

I have come across a strange and nit-picky issue with the PHP Imagick library's resizeImage and scaleImage methods. (client is unhappy, understandably as they are a photographer)

Whenever an image is resized, it seems that the image becomes very slightly compressed, and dark areas become slightly pixelated due to this compression. This happens even if I tell it to render at full quality as I will explain below.

Firstly, here is an example, including a 4x zoomed version where it is easier to see the problem: Compression Issue

At first I assumed this was some problem with the interpolation method, but when I dug deeper, I realized that the image infact still becomes compressed even when resized to exactly the same size!?.

The example shown above is a perfect example of that. It is a 100x100 image which has been resized to 100x100 using this code:

$image->resizeImage($this->width, 0, Imagick::FILTER_CATROM, 1);

This also appears to have the same results, even though I was told it would be better:

$image->scaleImage($this->width, 0, Imagick::FILTER_CATROM, 1); 

The fourth argument is blur (see PHP docs), which I understand is so that thumbnail images become aliased, however, even when I reduce this value to as small as 0.001, nothing happens.

Even when I add this code in to set the image quality to 100%, it still happens:

$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(100);

Can anyone explain to me why these artifacts are appearing in dark areas of images, and how I can prevent this from happening? These images resize perfectly fine in Photoshop, so it seems a unique issue with Imagick and not the image itself being unsuitable.

As I said, I know this is nit-picking, however my client is in fact a photographer and pristine image quality is of high importance to them.

Was it helpful?

Solution

Try using a different filter, the slower ones supposedly give better results.

OTHER TIPS

I was also facing the same issue and still unable to remove the blur from the image. tried all combinations. but finally i used Sharpens.

$viewport->unsharpMaskImage(0, 0.5, 1, 0);

and this looks better. This is an additional.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top