Why does imagemagick convert increases file-size - image-processing

I am using ImageMagick to convert png files to tiff. But after conversion the file size seems to increase by a huge amount? Any suggestion on what am i doing wrong here?
Command that I am using for conversion is : convert tiftest1.png tiftest2.png output_file.tif

PNG files are analysed (filtered) on a line-by-line basis to see how best each line can be compressed relative to the previous one, then compressed. TIFF files, in general, are not.
You need to consider whether you can accept lossless or lossy compression and then tell the TIFF encoder.
If only lossless compression is acceptable:
magick input1.png input2.png -compress LZW result.tif
If lossy compression is acceptable (and compatible with downstream needs):
magick input1.png input2.png -compress JPEG result.tif
Check actual compression used in a file with:
magick identify -verbose image.tif
Check available types of compression with:
magick identify -list compress

When converting to tiff, ImageMagick produces a non-compressed file by default. You can tell it to use LZW or ZIP or JPEG or other compressions. PNG is always compressed.

Related

Image Magick - How to compress for Google page speed?

I'm trying to find the right command for compressing png and jpg files good enough for Google Page speed.
I'm using the following from my OSX termial:
convert -strip -quality 85 imagesource.png imagesource_optimized.png
The result is no difference in file size between the original and "optimized version. Am Is there a different command I can use?
Compression is fundamentally different between PNG and JPEG because PNG is lossless and JPEG is lossy.
With a JPEG the -quality parameter specifies how much quality should be retained.
With a PNG file, the -quality parameter specifies the strategy and the amount of time/effort zlib can spend to optimise your image - think gzip --best versus gzip --fast.
See https://www.imagemagick.org/script/command-line-options.php#quality
For PNG, I suggest pngcrush which you can install with homebrew using:
brew install pngcrush
For JPEG, either use -quality or specify a maximum size:
# Specify by quality
convert input.jpg -strip -quality 75% output.jpg
# Specify maximum size
convert input.jpg -strip -define jpeg:extent=300k output.jpg
Compression is fundamentally different between PNG and JPEG because PNG is lossless and JPEG is lossy.

how to convert scanned jpg files to pbm format losslessly?

Using ImageMagick's convert utility to convert some scanned jpg files to pbm files.
However, even if the option -quality 100 is used, the pbm's resolution still looks worse than the original scanned jpg file.
Worse, the scanned jpg file is a colored one, while the converted pbm is black and white.
Info of original jpg:
image size: 2256 × 1568 pixels
dpi: 300 pixels/inch
color model: RGB
info of the converted pbm:
image size: 2256 × 1568 pixels
dpi: 72 pixels/inch
color model: Gray
Currently, here is what I did to convert the format:
qiang#bonjour:~/scan$ convert scan000.jpg scan000.pbm
Am I missing any option to use with convert? As I mentioned earlier, -quality 100 had been tried, but to no avail.
Using ImageMagick, I think you want to output to PPM not PBM. Try
convert image.jpg image.ppm
or try the ascii version by using
convert image.jpg -compress none image.ppm
PBM is binary (black/white) and PGM is grayscale. If you want to keep color, then you need to use PPM.
Unfortunately, I believe that ImageMagick can only read DJVU format images. So you cannot write to it directly from ImageMagick.

How to convert a jpg into a 24-bit uncompressed BMP 4.0?

I've tried using image magic but it converts the image into a compressed format and most of the online conversion tools are also doing the same thing.
Is there some way i could achieve this in image magic or anywhere else?
Use the ImageMagick "-compress none" option to prevent compression, and use "-define bmp:format=bmp4" to force BMP4.0:
convert in.jpg -define bmp:format=bmp4 -compress none out.bmp
You can omit defining the bmp4 format because that's the currently the default BMP output format for ImageMagick anyhow.
Add "-alpha on" if you need RGBA instead of RGB pixels.
See the ImageMagick documentation for the -compress and -define options.

Lossless YCbCr Tiff?

My goal is to create a Tiff image that natively holds uncompressed (or with lossless compression) YCbCr data inside (since the original image is YUV420 and IMO it would be a poor choice to upsample and convert to RGB).
I’m able to create (using imagemagick for instance) a valid YCbCr Tiff with a JPEG compressed data. When I try uncompressed / deflate / lzw I get a broken image (neither windows image viewer nor photoshop can open it). On page 94 of the TIFF 6.0 spec (under “Minimum Requirements for YCbCr Images”):
Compression = none (1), LZW (5) or JPEG (6). SHORT.
What’s wrong? Is there a Tiff extension which says that YCbCr color space is supported only when using jpeg compression?
Thanks,
Mark.
Command that works:
convert infileRGB.tif -colorspace ycbcr -compress jpeg outfileYCbCr.tif
Commands that don't work (broken tiff):
convert infileRGB.tif -colorspace ycbcr -compress none outfileYCbCr.tif
convert infileRGB.tif -colorspace ycbcr -compress lzw outfileYCbCr.tif

Converting .eps to .jpg

Our print team saves raster images as .eps files. We need to convert about 11000 .eps to .jpg. We are using ImageMagick (with Ghostprint) on Linux. The conversion occurs but the resulting .jpg is not the same size as the source .eps - It's about 1/2 the size. Probably a problem converting a vector to a raster. Any way to solve this?
Your using the default resolution (72dpi). use the -density option to specify a dpi to convert.
convert -density 300 /path/to/file.eps -flatten /path/to/file/.jpg;

Resources