Problem with convert - tiff to jpg

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?".
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Problem with convert - tiff to jpg

Post by zaratol »

Hello together,

ich have severall tiff Images which i want to convert to jpg

these Tiff Files can either have a transparent Background and/or an additional Alpha Channel

Example File with Transparent background: http://home.arcor.de/durius.obsidian/transparent.tif
Example File with Alpha Channel: http://home.arcor.de/durius.obsidian/alpha2.tif

I started with a simple conversion: convert transparent.tif -resize 400x400 transparent.jpg http://home.arcor.de/durius.obsidian/transparent.jpg

Problem: Black Background. Ok i set background to white:

convert transparent.tif -background white -flatten -resize 400x400 transparent_white.jpg http://home.arcor.de/durius.obsidian/tr ... _white.jpg

looks fine, next image:

convert alpha2.tif -background white -resize 400x400 alpha_white.jpg http://home.arcor.de/durius.obsidian/alpha_white.jpg

Problem: the alphaChannel i used as mask, ok so no alpha channel:

convert -alpha off alpha2.tif -background white -resize 400x400 alpha_white_alpha_off.jpg http://home.arcor.de/durius.obsidian/al ... ha_off.jpg

looks fine, but can this command be used for the first image?

convert -alpha off transparent.tif -background white -resize 400x400 transparant_white_alpha_off.jpg http://home.arcor.de/durius.obsidian/tr ... ha_off.jpg


Problem: Background is black again. So my question: Is there a command line that would work on both images?


I must admit, that the transparent.tif is possible broken, because with other tiff Images with transparancies i get better results. Or have i found a missing feature? :-)




ImageMagick version is:

convert -version
Version: ImageMagick 6.6.1-4 2010-04-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with convert - tiff to jpg

Post by fmw42 »

JPG does NOT support transparency. Use GIF or PNG. If you want jpg, then you have to do what you did making the background white

convert alpha2.tif -resize 400x400 -background white -flatten alpha2_white.jpg
convert transparent.tif -resize 400x400 -background white -flatten transparent_white.jpg

otherwise

convert alpha2.tif -resize 400x400 alpha2.png
convert transparent.tif -resize 400x400 transparent.png

will leave it transparent
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Re: Problem with convert - tiff to jpg

Post by zaratol »

Well this is funny

while convert transparent.tif -resize 400x400 transparent.png http://home.arcor.de/durius.obsidian/transparent.png

has a transparent background

convert transparent.tif -resize 400x400 transparent2.tif http://home.arcor.de/durius.obsidian/transparent2.tif

has a black background.

I also uploaded: convert alpha2.tif -resize 400x400 -background white -flatten alpha2_white.jpg http://home.arcor.de/durius.obsidian/alpha2_white.jpg sorry, i forgot the flatten option but this still doen't look anything near the original image :-)

I will experiment with the png output.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with convert - tiff to jpg

Post by fmw42 »

looks the same to me.

this works fine for me on IM 6.6.1-4 Q16 Mac OSX Tiger

convert transparent.tif -resize 400x400 transparent_small.tif

and the result is still transparent.

What version of IM are you using, if old perhaps upgrade.
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Re: Problem with convert - tiff to jpg

Post by zaratol »

Im Version is: 6.6.1-4 Q16 Linux x86_64
Libtiff is : 3.8.2-7
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with convert - tiff to jpg

Post by fmw42 »

how are you viewing the result. perhaps the viewer does not know how to deal with transparency
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with convert - tiff to jpg

Post by snibgo »

No. Downloading and examining with Gimp shows it has a transparent black background. (The background is transparent. Using eyedropper or anti-erase reveals black.)
snibgo's IM pages: im.snibgo.com
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Re: Problem with convert - tiff to jpg

Post by zaratol »

Well i guess i put too much trust in photoshop cs3.

The question remains: can i convert both images with one command line to jpg with white background?

I'm not sure it is possible.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with convert - tiff to jpg

Post by snibgo »

The same command can replace transparency with white (more accurately, it places the image over a white background, so the white shows through fully- or partially-transparent pixels).

convert transparent.tif -resize 400x400 -background white -flatten transparent_w.jpg
convert alpha2.tif -resize 400x400 -background white -flatten alpha2_w.jpg

Note that alpha2.tif has a clipping path, which the above commands ignore. In this case it makes no difference, but you could safely add "-clip" before "-background" to both commands.
snibgo's IM pages: im.snibgo.com
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Re: Problem with convert - tiff to jpg

Post by zaratol »

I mad a screenshot alpha2.tif and alpha2_w.jpg side by side:

http://home.arcor.de/durius.obsidian/result.png

the bottom part is missing. So far i suspect the alpha channel "Alpha 1" is set to white, destroying parts of the image. Thas is what i descriped earlier as is said : "alphaChannel i used as mask"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with convert - tiff to jpg

Post by snibgo »

What program did you use to display the images?

Using Gimp on alpha2.tif, I find the pixels of the jar (and lettering and shadow) are transparent.

But Gimp gives a warning: "alpha channel type not defined for file D:\web\im\alpha2.tif. Assuming alpha is not premultiplied". This is, I think, the tiff:alpha:associated/unassociated flag.
snibgo's IM pages: im.snibgo.com
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Re: Problem with convert - tiff to jpg

Post by zaratol »

Again Photoshop CS3.

I also made a screenshoot displaying channel "Alpha 1": http://home.arcor.de/durius.obsidian/alpha2_ps_view.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with convert - tiff to jpg

Post by fmw42 »

You have a useless alpha channel. Just turn it off.

convert alpha2.tif -alpha off alpha2_aoff.tif

Unless all you want is the lid. then

convert alpha2.tif -background white -flatten alpha2_white.tif
Last edited by fmw42 on 2010-04-23T09:14:30-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with convert - tiff to jpg

Post by snibgo »

Yes, Gimp shows the same: the lid is opaque, and the rest is transparent.
snibgo's IM pages: im.snibgo.com
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Re: Problem with convert - tiff to jpg

Post by zaratol »

i really would love to just turn off the alpha channel. But then the first image gets a black background again:
Problem: the alphaChannel i used as mask, ok so no alpha channel:

convert -alpha off alpha2.tif -background white -resize 400x400 alpha_white_alpha_off.jpg http://home.arcor.de/durius.obsidian/al ... ha_off.jpg

looks fine, but can this command be used for the first image?

convert -alpha off transparent.tif -background white -resize 400x400 transparant_white_alpha_off.jpg http://home.arcor.de/durius.obsidian/tr ... ha_off.jpg
and i need it one command line for both images, if it can' t be done; well :?
Post Reply