gmm
gmm

Reputation: 1030

ImageMagick convert tif to png or jpeg producing larger images

I have a lot of tif images I would like to convert to a web friendly format. Ive been playing a little bit with imagemagick (and a couple other libraries) to try to convert them, but the resulting image is a lot larger than the original, uncompressed image.

For example:

1.tif - 348.2kB
1.png - 781.7 kB
1.jpg - 429.1 kb

2.tif - 49.8 kB
2.png - 76.2 kB
2.jpg 900.4 kB

3.tif 7.7 kB
3.png 21.4 kB
3.jpg 191.3 kB

The command im using:

convert *.tif -set filename: "%t" %[filename:].jpg

Im not an expert, but I dont understand how passing from an uncompressed source image to a compressed one makes the size explode. Any idea of what is happening?

After running the proposed command

identify -format "%f: size: %B, compression: %C\n" *png *tif *jpg

I get the following output

00000001.png: size: 104522, compression: Zip
00000002.png: size: 23565, compression: Zip
00000003.png: size: 58936, compression: Zip
00000001.tif: size: 74122, compression: Group4
00000002.tif: size: 10946, compression: Group4
00000003.tif: size: 29702, compression: Group4
00000001.jpg: size: 1011535, compression: JPEG
00000002.jpg: size: 226068, compression: JPEG
00000003.jpg: size: 457045, compression: JPEG

Upvotes: 0

Views: 3575

Answers (2)

user1259398
user1259398

Reputation: 31

I guess it depends on the source content?

I converted a fax file I got with the command above convert FAX_*.tif -depth 1 00000001_1bit.png

and got source: 72K; resulting .png: 48K

Upvotes: 0

Mark Setchell
Mark Setchell

Reputation: 208052

It's hard to say what is happening without seeing your images - not all software uses the same compression method, or quality and some formats, such as PNG are lossless.

As a first attempt, try running this command to check the filename, file size, compression type of all your images:

identify -format "%f: size: %B, compression: %C\n" *png *tif *jpg

Sample Output

zHZB9.png: size: 1849, compression: Zip
result.tif: size: 290078, compression: None
z.tif: size: 213682, compression: LZW
sky.jpg: size: 88162, compression: JPEG
z.jpg: size: 8122, compression: JPEG

Now you can see the numbers you can decide what you want to address. So, to get a list of all the compression types you can use:

identify -list compress

Sample Output

B44A
B44
BZip
DWAA
DWAB
DXT1
DXT3
DXT5
Fax
Group4
JBIG1
JBIG2
JPEG2000
JPEG
LosslessJPEG
Lossless
LZMA
LZW
None
Piz
Pxr24
RLE
RunlengthEncoded
WebP
ZipS
Zip
Zstd

Now, you can experiment, e.g. by making some TIFFs with different settings:

convert -size 1024x768 gradient: 1.tif
convert -size 1024x768 gradient: -compress lzw 2.tif
convert -size 1024x768 gradient: -compress jpeg  3.tif
convert -size 1024x768 gradient: -compress jpeg  -quality 40 4.tif

Now check:

1.tif: size: 1573138, compression: None
2.tif: size: 6316, compression: LZW
3.tif: size: 17520, compression: JPEG
4.tif: size: 9830, compression: JPEG

Upvotes: 2

Related Questions