IM 6.0.7 coloring transparency in png to jpg fails

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
Paramäleon

IM 6.0.7 coloring transparency in png to jpg fails

Post by Paramäleon »

I tried the following:

convert file.png -background \#FFFFFF -flatten -resize '192x128>' -quality 50 small.jpg

to convert a PNG file with transparency to JPG. The transparent area stays black in the result however. What's wrong?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM 6.0.7 coloring transparency in png to jpg fails

Post by fmw42 »

Try this and go from there. This works. Learned it from Anthony Thyssen

Recoloring transparent areas

# create test image (red square surrounded by black)
convert -size 100x100 xc:red -bordercolor black -border 50 tmp.png

# to make red transparent
convert tmp.png -transparent red tmp1.png

# to make transparent red (-opaque is -channel effected)
convert tmp1.png -channel RGBA -fill red -opaque none tmp2.jpg
Paramäleon

Re: IM 6.0.7 coloring transparency in png to jpg fails

Post by Paramäleon »

It finally goes! Whow, great. Thanks a lot!

Note that images without transparency get disrupted by this, so it can't be used in batch on mixed sources!

Everybody please note, too, that I took the failing way using the -flatten operator from some manual here on PNG to JPG, which is obviously wrong then. Maybe someone wants to update that...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: IM 6.0.7 coloring transparency in png to jpg fails

Post by anthony »

Your real problem however is you IM is very very old. At least 3 to 4 years old. I suggest you upgrade before you start complaining about the many other problems that have long since been fixed.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply