Page 1 of 2

Problem with convert - tiff to jpg

Posted: 2010-04-22T07:52:43-07:00
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

Re: Problem with convert - tiff to jpg

Posted: 2010-04-22T09:39:08-07:00
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

Re: Problem with convert - tiff to jpg

Posted: 2010-04-22T10:06:37-07:00
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.

Re: Problem with convert - tiff to jpg

Posted: 2010-04-22T10:52:41-07:00
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.

Re: Problem with convert - tiff to jpg

Posted: 2010-04-22T11:57:04-07:00
by zaratol
Im Version is: 6.6.1-4 Q16 Linux x86_64
Libtiff is : 3.8.2-7

Re: Problem with convert - tiff to jpg

Posted: 2010-04-22T12:03:05-07:00
by fmw42
how are you viewing the result. perhaps the viewer does not know how to deal with transparency

Re: Problem with convert - tiff to jpg

Posted: 2010-04-22T13:27:09-07:00
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.)

Re: Problem with convert - tiff to jpg

Posted: 2010-04-23T06:33:34-07:00
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.

Re: Problem with convert - tiff to jpg

Posted: 2010-04-23T07:19:15-07:00
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.

Re: Problem with convert - tiff to jpg

Posted: 2010-04-23T08:42:10-07:00
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"

Re: Problem with convert - tiff to jpg

Posted: 2010-04-23T08:59:26-07:00
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.

Re: Problem with convert - tiff to jpg

Posted: 2010-04-23T09:10:30-07:00
by zaratol
Again Photoshop CS3.

I also made a screenshoot displaying channel "Alpha 1": http://home.arcor.de/durius.obsidian/alpha2_ps_view.png

Re: Problem with convert - tiff to jpg

Posted: 2010-04-23T09:12:50-07:00
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

Re: Problem with convert - tiff to jpg

Posted: 2010-04-23T09:14:04-07:00
by snibgo
Yes, Gimp shows the same: the lid is opaque, and the rest is transparent.

Re: Problem with convert - tiff to jpg

Posted: 2010-04-23T09:21:44-07:00
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 :?