png to gif - 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
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

png to gif - Transparency

Post by agriz »

Code: Select all

convert a.png -background LightSteelBlue -flatten  a_overlay.gif
This was the example code which i found in imagemagick website.
Without using this -background LightsteelBlue, can't we achieve this effect?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: png to gif - Transparency

Post by GeeMack »

agriz wrote:This was the example code which i found in imagemagick website.
Without using this -background LightsteelBlue, can't we achieve this effect?
Not quite sure what you're trying to do there, but with IM you can always use "none" as a color descriptor. That often works when you want transparent backgrounds, borders, etc. Maybe try "-background none".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png to gif - Transparency

Post by fmw42 »

agriz wrote:

Code: Select all

convert a.png -background LightSteelBlue -flatten  a_overlay.gif
This was the example code which i found in imagemagick website.
Without using this -background LightsteelBlue, can't we achieve this effect?

Please always provide your IM version and platform. Also an example of your input and your resulting output and explain why the command is not working the way you want. A pointer to where you found this code would also be helpful.

Please read the top-most post in this forum at viewtopic.php?f=1&t=9620.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png to gif - Transparency

Post by fmw42 »

PNG only has one layer. So if it has transparency, then I see no need for the background or flatten, unless you want to remove the transparency. So if you want to keep the transparency, then just do

Code: Select all

convert image.png image.gif
If you want to replace the transparency with some color, then you can do

Code: Select all

convert image.png -background skyblue -flatten image.gif
or

Code: Select all

convert image.png -background skyblue  -alpha remove -alpha off image.gif
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: png to gif - Transparency

Post by agriz »

It is not working sir
ImageMagick-6.7.8.9-13
Last edited by agriz on 2016-08-27T20:26:38-07:00, edited 1 time in total.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: png to gif - Transparency

Post by agriz »

Code: Select all

convert -size 70x60 xc:none -font Candice -pointsize 50 \
          -fill black -annotate +10+45 'A' -channel RGBA  -blur 0x5 \
          -fill white -stroke black -draw "text 5,40 'A'"   a.gif
Image

Code: Select all

convert -size 70x60 xc:none -font Candice -pointsize 50 \
          -fill black -annotate +10+45 'A' -channel RGBA  -blur 0x5 \
          -fill white -stroke black -draw "text 5,40 'A'"   a.png
Image

Code: Select all

convert a.png  a_overlay.gif
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png to gif - Transparency

Post by fmw42 »

PNG supports 8-bit transparency. But GIF only supports binary transparency. So your PNG shadow will be thresholded at about 50% when saving as GIF and you will get either fully transparent part shadow and full opaque part shadow. Since your transparency is black underneath the opaque part shows as black.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: png to gif - Transparency

Post by agriz »

Is there no way to use png to generate animated gif? When i use few layers of a.png with shadow, it becomes like the above image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png to gif - Transparency

Post by fmw42 »

No way if you keep transparency with smooth shadow. If you flatten transparent png images against some background color such as white, then the gifs will be fine.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: png to gif - Transparency

Post by agriz »

If i use imagemagick 7.0, and if i create gif by appending few jpg images, i get the right image size
If i use imagemagick 6.7 and if i create gif by appending the same jpg images, i get the wrong image size.

Sir, if i use identify -verbose info: image.gif

//if created in 6.7 - Should be about 300
[4] => Geometry: 29x490+0+0

Is there a chance that i can change the image width and height in the image information?
So when i use php's getimagesize($image) i will get the right image size.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png to gif - Transparency

Post by fmw42 »

Please don't change topics within a post. Please create a new post in the future. IM 6.7 is ancient (over 200 versions old) and might have a bug. No way to go back to fix the bug in IM 6.7. You might be able to use EXIFTOOL to make changes to the meta data if you need to correct the image. But if IM 7 works fine, then there must have been a bug in IM 6.7.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: png to gif - Transparency

Post by agriz »

Ok sir. I updated to IM 7. It is working good.
Post Reply