Page 1 of 1

rotating transparent gif, gives "jagged" border

Posted: 2008-08-10T04:25:20-07:00
by fommes
Hi there,

I am trying to overlay a transparent gif onto another gif (no animated) I use the following command:

Code: Select all

 "convert overlay_images/image.gif -background white -rotate 45 -transparent white overlay_images/tmpImages/rotation_1.gif"
When i then use the rotated gif and merge it onto a gif image the border seams to have left some white background pixels.

Here you can see an example: http://www.tom-it.nl/example.gif

Can anybody tell me if this is possible with better quality transparency ?

With regards,

Thomas.

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-10T11:32:15-07:00
by fmw42
add -fuzz 5% or whatever percent you want before -transparent white

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-11T00:23:40-07:00
by anthony
GIF has boolean transparency. As such it has aliases or 'staircase' like borders. Use PNG for the intermediate image, and not GIF.

See IM Examples, Common Image Formats, GIF
GIF Boolean Transparency
http://www.imagemagick.org/Usage/formats/#boolean_trans

Just about everything that follows on GIF is various methods to improve GIF output. If you don't plan on transparency in the final image, use PNG or MIFF for intermediate images, NEVER use GIF or JPEG for intermediate images.

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-11T00:26:41-07:00
by anthony
As for removing the background while keeping a properly aliased edge, There is no simple solution. A complex solution (which includes keeping shadow effects) is shown on
Masking with Anti-Aliased Edges
http://www.imagemagick.org/Usage/channe ... antialised

It would be nice for this technique to become a builtin IM command
where uses can just simply play with the fuzz percentages until that get a good anti-aliased border.

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-14T02:55:03-07:00
by fommes
Is it possible to convert te gifs on the fly and then rotate and merge them ?

It would be nice if you could give me some more info regarding the issue, i have made a webapp where people can upload their image (jpeg / gets converted to gif at the moment) then they can add different overlays to the image, as they click save the following process will be initiated:

send xml with changes to a php script
php script will create the nr of frames and merge the overlays on them
if the overlay is rotated then imagemagick will rotate the gif and merge it onto the image

all the frames are merged into an animated gif

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-14T17:00:56-07:00
by anthony
Looking at your example output again.

I believe the images with diagonal pixels, are already transparent when you then rotate them with a white background. As a result you end up with a line of semi-transparent white pixels along the edge of the rotated rectangle.

For those images rotate the image using a background of none.


BETTER STILL... Remove any existing background from the input image FIRST (if present), then rotate with background 'none', before overlaying. You will have less problems.

When that is solved you can go on with better background removal than just a some -fuzz factored color replacement or flood fill... See Replacing Colors in Images, and especially the later section of flood filling, as well as Transparency Masking and Background Removal

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-20T10:50:02-07:00
by fommes
Thanks for the advice the problem was i used -background white transparent -white wich caused the jagged borders now i use -background none

I have one more question though, i use image magick to split my animated gifs into seperate frames, i use the following command within php:

exec("/usr/bin/convert $name -scene 1 +adjoin frame_%00d.gif");

where $name = the name of the gif.gif

This works for the most gifs, but for some gifs it doesnt i think the gifs that dont split correctly are create different, with masks or something like it, when the gif is "different" the frames look like this:

Frame1
Image

Frame2
Image

original:

Image

Is it possible to split these gifs correctly ?

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-20T18:21:02-07:00
by fmw42
I believe that to get complete individual frames you need to use -coalesce; otherwise you get only the partial updates to each frame

see http://www.imagemagick.org/Usage/anim_basics/#coalesce

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-20T22:02:01-07:00
by anthony
That is correct. Each frame of a GIF animation can be either just a small area (Frame Optimization), or even just the pixels that changed (Compression/Transparency Optimization).

The later could be even more complex with partial transparency optimizations which improves the LZW compression of the GIF than a full transparency optimization does.


If you want each of the frames to appear complete, (like a on an old film strip) then Coalease them, and re-optimize the animation when you finally put things back together.

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-08-20T22:46:58-07:00
by fommes
thanks a lot i will give it a try tonight!

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-11-21T07:17:30-07:00
by fommes
Hi there,

I'm back the jagged border is gone when i rotate the images i now use the following :

convert imageframe.gif -background none -rotate $rotation -transparent white overlay_images/tmpImages/rotation_{$tempimage}_{$i}.gif"

Now what i do in short, i make 4 frames with this and then merge the 4 on a certain background and then merge the whole into one animated gif and the result you wil get is :

non rotated animation on a background:
http://fotobling.fotopocket.nl/view.php?id=42

rotated using imagemagick on a background:
http://fotobling.fotopocket.nl/view.php?id=41

As you can see the product quality of the rotated version is lower then without a rotated gif it seems that the palletes of the 4 merged gifs are different somehow, is there some method i can use to stop the pixels from changing color ?

Thanks in advance!

Re: rotating transparent gif, gives "jagged" border

Posted: 2008-11-21T11:58:55-07:00
by fmw42
fommes wrote:Hi there,

I am trying to overlay a transparent gif onto another gif (no animated) I use the following command:

Code: Select all

 "convert overlay_images/image.gif -background white -rotate 45 -transparent white overlay_images/tmpImages/rotation_1.gif"
When i then use the rotated gif and merge it onto a gif image the border seams to have left some white background pixels.

Here you can see an example: http://www.tom-it.nl/example.gif

Can anybody tell me if this is possible with better quality transparency ?

With regards,

Thomas.

The border is due to anti-aliasing in the rotate against a white background. So to make white transparent, you need to use -fuzz to make some percent different from white also be transparent.

The other way is to make to outer area of the rotate transparent to begin with using color none. And I would suggest using png rather than gif for a smoother edge.

convert image.png -background none -rotate 45 image_r45.png

Then composite that with your background image