Resizing PNG removes the opacity/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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing PNG removes the opacity/transparency

Post by fmw42 »

This works just fine for me on IM 6.4.2-2


convert logo: -transparent white logo_trans.png
convert logo_trans.png -resize 50% logo_trans_50.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Resizing PNG removes the opacity/transparency

Post by anthony »

What format did you write it in? As you mentioned GIF you are obviously writing in other formats as well as PNG.

JPEG does not support transparency, and is lossy (not exact colors)
GIF only supports boolean transparency, and a small number of colors.

See IM examples, Common Image Formats for more details of all three image file formats.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
roach

Re: Resizing PNG removes the opacity/transparency

Post by roach »

I'm having the same problem described in the Title. It looks as though this thread has rotted away (some posts are missing?)

Anyways, I need to take an existing "watermark" image (PNG file, with Transparency), resize it to an appropriate dimension for the "target" image (the image I'm trying to watermark), then composite it over the target image, and save to an output file.

Step 1, Resize the watermark (.PNG overlay) file:

Code: Select all

convert watermark.png -resize 640x480^ -gravity center -extent 640x480 watermark_temp.png
[code]

Step 2, apply the watermark to the target image:
[code]
composite -gravity center watermark_temp.png inputfile.jpg outputfile.jpg
[code]

Seems to work, but watermark_temp.png has all of it's transparency converted to plain white, so the outputfile.jpg image basically looks like a watermark, on a white background.

I'm using ImageMagick 6.5.6-Q16 on Windows 7, via the OLE object.

Anyone have any ideas?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Resizing PNG removes the opacity/transparency

Post by Bonzo »

Try:

Code: Select all

convert inputfile.jpg ( watermark.png -resize 640x480^ ) -gravity center -composite over -matte outputfile.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing PNG removes the opacity/transparency

Post by fmw42 »

try enabling the alpha channel as follows on your watermark image

convert inputfile.jpg \( watermark.png -channel rgba -alpha on -resize '640x480^' \) -gravity center -composite over outputfile.jpg

you can use -matte rather than -alpha on if your system is too old.

if on windows see http://www.imagemagick.org/Usage/windows/
roach

Re: Resizing PNG removes the opacity/transparency

Post by roach »

Thanks Bonzo! Turns out removing the "-extent 640x480" was the key. Something about the "extent" was removing the alpha channel. Since I didn't need it, I took it out, and everything works fine now.

thanks!
Post Reply