Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why smaller PNG image takes up more space than the original after getting resized by GraphicsMagic

The original PNG image is 800x1200 and takes up about 34K. After the images is resized by GraphicsMagick to 320x480 size, the resulting images takes up approximately 37K. (For comparison, if the image is resized with Paint on Windows 7 then the resulting image is 40K.) What gives? The whole point of resizing an image was to save space. How should GraphicsMagick be used to shrink the image size?

like image 814
shargors Avatar asked Dec 23 '12 04:12

shargors


People also ask

Does PNG lose quality when resized?

To resize a PNG file without losing quality, use a lossless compression tool that supports transparency and PNG files. There are many compression tools available online that can do this for free.

Does PNG take more space?

Disadvantages of PNGs One of the reasons why JPG images are widely used on the web is the friendly file size. PNG images undergo a different type of image compression that reduces the file size, but not to the same degree as a JPG file.

Can a PNG image be resized?

Resize your PNG images for free. Edit your PNG images for free, on the fly with our photo resizer tool. Select from preset sizes and download instantly.


1 Answers

PNG is a lossless format and compresses the image data by first performing a step called prediction and then applying the same algorithm used in zlib. The prediction step is a crucial one in order to effectively compress the file, and it is based on the values of earlier neighbors pixels.

So, suppose you have a large PNG in black & white (by that I really mean only black and white, some people confuse that by grayscale sometimes). Also suppose it is not a tiny checkerboard pattern. In many regions of this image, you will have a relatively large white region, and then a relatively large black region, and so on. When the predictor is inside one of these large regions, it has no trouble to correctly predict that the current pixel intensity is exactly equal to the last one. This makes it easier to better compress the data describing your image.

Now, let us downscale this black & white image using some resampling filter different than nearest neighbor (let's say Lanczos). This has a great chance to turn your black & white image into a grayscale one, which has a much greater intensity range. This potentially makes the job of the predictor much harder, and thus the final file size might be larger.

For instance here is a black & white 256x256 PNG image which takes 5440 bytes, a resizing of it (using 3-lobed Lanczos) to 120x120 which now takes 7658 bytes, and another resizing (using nearest neighbor) to 120x120 which occupies 2467 bytes.

enter image description hereenter image description hereenter image description here

like image 147
mmgp Avatar answered Sep 20 '22 00:09

mmgp