Page 1 of 1
Converting transparent PNG
Posted: 2011-07-15T07:33:30-07:00
by emafuma
Hi, I'm trying to convert a PNG with transparency, but if I add vignette I have my transparency replaced with black.
Is it possible to replace with white
I tried:
convert agrate_brianza.png -background transparent -transparent-color white -gravity Center -crop 150.0x150.0+0+0 -resize '136.0' -opaque white -fill white -transparent white -vignette 1x1+2+2 agg3.png
But didn't work.
Thanks in advance
Re: Converting transparent PNG
Posted: 2011-07-15T09:52:46-07:00
by fmw42
post a link to your image. also explain what you want to happen with the transparency. it is hard to know what you are trying to do without seeing your image and your bad result and know what you want for a good result. also let us know what version of IM and platform you are using.
you certainly have too many combinations of -fill, -opaque, -transparent (and often in the wrong order) and -transparent color will do nothing.
If I understand, then try
convert image -crop ... -resize ... -alpha off -vignette ... -alpha on resultimage
Re: Converting transparent PNG
Posted: 2011-07-18T01:09:17-07:00
by emafuma
Hi,
Thanks for replying, so this is the pic in question:
http://dl.dropbox.com/u/1069056/agrate_brianza.png
And this is the command line:
convert agrate_brianza.png -background transparent -transparent-color white -gravity Center -crop 150.0x150.0+0+0 -resize '136.0' -opaque white -fill white -transparent white -vignette 1x1+2+2 agg3.png
Thanks for any tips on that.
Bye
Re: Converting transparent PNG
Posted: 2011-07-18T11:05:34-07:00
by fmw42
Both these work for me:
First line: crop and resize your image
Second line: clone the result and extract the alpha channel
Third line: clone the alpha channel, colorize with black then draw a white circle
Fourth line: take the previous two (alpha channel) images and multiply them
Fifth line: put the multiplied alpha channel back into your cropped and resized image.
convert \( agrate_brianza.png -gravity Center -crop 150x150+0+0 -resize '136' \) \
\( +clone -alpha extract \) \
\( +clone -fill black -colorize 100% -fill white -draw "circle 68,68 68,136" \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 1,2 -alpha off -compose copy_opacity -composite agrate_brianza1.png
Same as above, but use vignette rather than drawing a circle
convert \( agrate_brianza.png -gravity Center -crop 150x150+0+0 -resize '136' \) \
\( +clone -alpha extract \) \
\( +clone -fill white -colorize 100% -background black -vignette 1x1+2+2 \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 1,2 -alpha off -compose copy_opacity -composite agrate_brianza2.png
Re: Converting transparent PNG
Posted: 2011-07-18T12:03:37-07:00
by emafuma
that works for me too! Thank you very much.
Re: Converting transparent PNG
Posted: 2011-09-22T03:32:08-07:00
by emafuma
I tried again, but the pic I get has transparent background while I want to have it white. Is it possible? Thanks
Re: Converting transparent PNG
Posted: 2011-09-22T09:58:40-07:00
by fmw42
add -compose over -background white -flatten just before your output image. see if that gets you what you want.
I will try to give you a shorter version later today.
Re: Converting transparent PNG
Posted: 2011-09-22T10:09:48-07:00
by emafuma
Thanks for replying
I did:
convert \( agrate_brianza.png -gravity Center -crop 150x150+0+0 -resize '136' \) \( +clone -alpha extract \) \( +clone -fill black -colorize 100% -fill white -draw "circle 68,68 68,136" \) \( -clone 1 -clone 2 -compose multiply -composite \) -delete 1,2 -alpha off -compose copy_opacity -composite -compose over -background white -flatten agrate_brianza89.png
but the resulting image is no longer a circle
Re: Converting transparent PNG
Posted: 2011-09-22T11:28:41-07:00
by fmw42
what color do you want outside the circle and what color inside the circle?
Re: Converting transparent PNG
Posted: 2011-09-22T23:52:04-07:00
by emafuma
It Should be white inside and tranparent outside (I mean it's the transparency that makes the pic looks circular)
Thanks
Re: Converting transparent PNG
Posted: 2011-09-23T10:02:57-07:00
by fmw42
Try this. If that is not what you want, then let me know further.
convert \( agrate_brianza.png -gravity Center -crop 150x150+0+0 +repage \
-resize 136 -background white -flatten \) \
\( +clone -fill black -colorize 100% -fill white -draw "circle 68,68 68,136" \) \
-alpha off -compose copy_opacity -composite agrate_brianza4.png
The +repage is needed to remove the virtual canvas so that the canvas size is the same as the image size at 150x150 so that your resize will end up 136x136 without distortion.
The -background white -flatten makes the background white. Then the circle mask the outside as transparent when put into the alpha channel.