Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick - Smaller resized image is a much larger file size

In ImageMagick, I'm running a:
convert -trim -density 200 myfile.tif -resize 70% myconvertedfile.png

If I remove -resize 70%, the image size is only 78,527.
However, when the file is stored at 70%, the file size is 860,504

What makes the smaller image a larger file size, and is there a way to decrease the file size without quality loss?

like image 855
heyitsmyusername Avatar asked Oct 26 '25 23:10

heyitsmyusername


2 Answers

Most likely your smaller image has a larger number of colors due to interpolation of pixels during the resizing operation. To resize without adding colors, use -sample 70% instead of -resize 70%.

like image 178
Glenn Randers-Pehrson Avatar answered Oct 29 '25 13:10

Glenn Randers-Pehrson


Your tiff may be compressed, Imagemagick, then decompresses and outputs to png. The resulting png compression may produce a file size larger than your tiff compression. Also, the tif may be 8-bit color, but when resized, it gets new colors and so must be saved as 24-bit color into PNG. I suspect this latter.

Also you should use proper ImageMagick syntax, which reads the input image before applying settings and then operators. However, ImageMagick 6 is forgiving in this regard.

convert myfile.tif -trim -resize 70% -density 200 myconvertedfile.png

If you want an 8-bit result, then you can use PNG8:myconvertedfile.png for your output.

When specifying density, you should specify units. PNG only stores units of pixels per centimeter, but will convert density and pixels per inch into the correct pixels per centimeter.

You could replace -resize with -sample and not interpolate pixels to new values. -sample will just grab every nth pixel.

like image 39
fmw42 Avatar answered Oct 29 '25 13:10

fmw42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!