Why do Imagemagick or GraphicsMagick increase the MB size of my PNG image when resizing to a smaller dimension?

StackOverflow https://stackoverflow.com/questions/21214859

  •  29-09-2022
  •  | 
  •  

Domanda

I need to convert from png to png.

I am using ImageMagick 6.8.7-7 on Mac OS X to decrease the dimension of my png.

Here is an exact example : start.png : 20866 × 8957 = 6.6 MB

start.png is a detailed floor plan just black and white

convert start.png -resize 16384x7033 out.png

Result is out.png 16384 × 7033 = 36.9 MB (even convert start.png -resize 16384x7033 out.jpg => out.jpg 22.7MB)

If I apply "pngquant" to out.png I can reduce to 15MB

Why does this increase happen?

I am looking for a option on convert which will not increase the size of out.png?

EDIT Maybe it helps if I provide more infos... I executed "identify -verbose" on both files and got following output:


Image: start.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 20866x8957+0+0
Resolution: 98.43x98.43
Print size: 211.988x90.9987
Units: PixelsPerCentimeter
Type: Palette
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2014-01-19T09:06:05+01:00
date:modify: 2014-01-17T11:48:05+01:00
png:iCCP: chunk was found
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 2

png:IHDR.color_type: 2 (Truecolor)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 20866, 8957
png:pHYs: x_res=9843, y_res=9843, units=1`
Profiles:
Profile-icc: 2576 bytes
Artifacts:
filename: start.png
verbose: true
Tainted: False
Filesize: 6.603MB
Number pixels: 186.9M
Pixels per second: 41.63MB
User time: 4.480u
Elapsed time: 0:05.490

**OUT.png

Image: out.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 16384x7033+0+0
Resolution: 98.43x98.43
Print size: 166.453x71.4518
Units: PixelsPerCentimeter
Type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2014-01-19T09:55:41+01:00
date:modify: 2014-01-19T09:55:41+01:00
png:bKGD: chunk was found (see Background color, above)
png:cHRM: chunk was found (see Chromaticity, above)
png:iCCP: chunk was found
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 16384, 7033
png:pHYs: x_res=9843, y_res=9843, units=1
png:text: 3 tEXt/zTXt/iTXt chunks were found
Profiles:
Profile-icc: 2576 bytes
Artifacts:
filename: out.png
verbose: true
Tainted: False
Filesize: 36.89MB
Number pixels: 115.2M
Pixels per second: 38.54MB
User time: 2.980u
Elapsed time: 0:03.990
Version: ImageMagick 6.8.7-7 Q16 x86_6*
È stato utile?

Soluzione

The reason the filesize increases is that your resize operation increases the number of colors. You could replace "resize WxH" with "-sample WxH" to only use the existing (black and white) colors.

If you're using ImageMagick, you might as well remove the ICC profile too, with "-define png:exclude-chunk=iCCP", because it's not of much use in a black-and-white image. This option isn't yet available in GraphicsMagick.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top