Page 1 of 1

PNG Compression

Posted: 2008-07-23T05:58:40-07:00
by marc_gfx
I am using Imagick to resize uploaded images. I have noticed that a large PNG24 I uploaded (2000*2249 pixels at 208kb) increases in size after resizing. The goal of resizing is really to reduce the load on the server :)

The new values are 1024*910 pixels at 460kb. So for a quarter of the pixels it uses more than double the amount of file space.

I compared this to compression done with photoshop6 and it reduces the image to ~152kb, so something must be going wrong. I assume there are options I have not found yet?

I have tried $im->setCompression (Imagick::COMPRESSION_ZIP) with no change in the result.

Re: PNG Compression

Posted: 2008-07-23T09:24:09-07:00
by marc_gfx
I found a solution in the forum (I thought). But it wont work probably because of this:
There seems to be a slight problem with setting image or channel depth. Using Q16, setting the depth to 8 bit, you will have a 16 bit file.
Doesn't matter with better previews / image processing programs. With Win systems the display for TIFF files is a kind of psychedelic art.
This took me hours until I did check with PhotoShop. Besides: even if it works with RGB and PNG files, this consumes resources. Have a look on file size.
Only way out: change to Q8.
IMHO there is no way to run Q8 and Q16 simultaneously.
The above said concerns also setImageDepth.
is there a disadvantage if I use Q8? or does it make more sense anyway for websites?

Re: PNG Compression

Posted: 2008-07-23T11:51:22-07:00
by marc_gfx
I will continue to answer my own questions ;) ... I have installed Q8 and the PNG file is now 130kb after resizing. I guess Imagick Q16 has a little bug in the setImageDepth function (in the version I have).

Re: PNG Compression

Posted: 2008-09-24T07:54:25-07:00
by vitty
Hello,

I have a simmilar problem as above.

source file: 24-bits per pixel RGB image (each channel 8-bits per pixel)
I use the scale method for resizing images and then I write the image to the disk.
output file: 48-bits per pixel RGB (each channel 8-bits per pixel)

This happens for PNG files. (not JPG files)
If I use setImageDepth(8) then it doesn't change the output depth (still 16). The output PNG files are so big because 16-bit output. :-(

This looks like a bug.

Linux OS
ImageMagick version ImageMagick 6.3.8 01/30/08 Q16
imagick module version 2.0.1

Thanks for help

Re: PNG Compression

Posted: 2008-09-24T08:38:26-07:00
by mkoppanen
Can you post code and example images? I can not reproduce this issue.

I am running ImageMagick 6.4.2.

Re: PNG Compression

Posted: 2008-09-25T01:49:17-07:00
by vitty
Hi,

below is the code and I've attached test images.

Code: Select all

$im_handler = new Imagick();
$im_handler->readImage( '/var/www/html/test/png/input.png' );
$im_handler->scaleImage( 640, 512 );
$im_handler->writeImage( '/var/www/html/test/png/output.png' );
$im_handler->destroy(); 

$im_handler_2 = new Imagick();
$im_handler_2->readImage( '/var/www/html/test/png/input.png' );
$im_handler_2->scaleImage( 640, 512 );
$im_handler_2->setImageDepth( 8 );
$im_handler_2->writeImage( '/var/www/html/test/png/output_2.png' );
$im_handler_2->destroy(); 

exec("/opt/ImageMagick/bin/convert \"/var/www/html/test/png/input.png\" -scale 640x512 -depth 8 \"/var/www/html/test/png/output_3.png\"",$output);
Linux OS
ImageMagick version ImageMagick 6.3.8 01/30/08 Q16
imagick module version 2.0.1

Re: PNG Compression

Posted: 2008-09-25T01:52:03-07:00
by vitty
another two output images

Re: PNG Compression

Posted: 2008-09-27T05:21:51-07:00
by mkoppanen
Hi,

unable to reproduce with ImageMagick 6.4.2. I will try with older version at some point.

Re: PNG Compression

Posted: 2008-09-29T12:10:29-07:00
by vitty
mkoppanen wrote:Hi,

unable to reproduce with ImageMagick 6.4.2. I will try with older version at some point.


Hi

it means that the problem is fixed in the newest version of imagick and image magick?

Re: PNG Compression

Posted: 2008-09-30T01:37:13-07:00
by mkoppanen
Can you try it with newer version? You can use ./configure --prefix=/opt/imagemagick_new or something similar so it won't mess your current installation.

Re: PNG Compression

Posted: 2008-10-15T05:52:19-07:00
by colnector
Optipng could be useful to optimize the resulting files anyway