Convert tiff to jpeg is creating several images when having transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
MisterJpa
Posts: 11
Joined: 2018-07-23T02:32:48-07:00
Authentication code: 1152

Convert tiff to jpeg is creating several images when having transparency

Post by MisterJpa »

Hello,

I'm beggining with Image Magick and I'm currently trying to convert and resize a TIFF file to a JPEG file, usually smaller than the original one.
I have two assets : bag.tif and book.tif
Running :
convert bag.tiff -resize 1280x1280 bag.jpg
is correctly doing the conversion.

However, running
convert book.tiff -resize 1280x1280 book.tiff is creating two images :
- One with a black background instead of the transparency (ok, why not as jpeg doesn't handle transparency)
- A second one which is "zoomed" on the non transparent part of the image

Cf:
Image

My goal is that the command generate only one jpeg image (and if possible with a white background instead of a black one.

Can someone explain why I have to image with this command when there is transparency and if possible, could you please provide me a command that will work for both conversion (bag and book) ?

Many thanks in advance,
MisterJpa
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert tiff to jpeg is creating several images when having transparency

Post by snibgo »

When asking questions, please always provide:
- the version number of IM you are using
- your platform
- links to your input image files

You say:
MisterJpa wrote:convert book.tiff -resize 1280x1280 book.tiff
Perhaps you intended to say the requested output is "book.jpg".

In your case, I suspect book.tiff contains two images, so you get two outputs. If you just want the first image, then use [0]. And you can flatten against any colour:

Code: Select all

convert book.tiff[0] -resize 1280x1280 -background White -layers Flatten book.jpg
snibgo's IM pages: im.snibgo.com
MisterJpa
Posts: 11
Joined: 2018-07-23T02:32:48-07:00
Authentication code: 1152

Re: Convert tiff to jpeg is creating several images when having transparency

Post by MisterJpa »

Hello @Snibgo,

Many thanks for your help.
The command that you provide is perfectly working in both case.

Sorry for the missing info at the beginning, I will provide them next time !
Post Reply