How to use common colormap for animated gif at php?

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
gydoesit

How to use common colormap for animated gif at php?

Post by gydoesit »

How to use common colormap for animated gif at php?

Per frame of animated gif has private colormap,it's 768 bytes(256 x 3).
This will add a lot of bytes.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to use common colormap for animated gif at php?

Post by anthony »

Basically you have a image sequence. When you save to GIF IM automatically color quantizes the images because GIF can only handle 256 colors. If the images are already within the 256 limits, no quantization or dithering is performed.

The latest few IM releases however seem to save a GIF with a common color map. Before this (when I wrote the IM Examples section on this) it used separate color maps. I know this as my 'hard to optimze' image (moving hole) is not producing seperate color tables, (I get a 0 local color table count for the IM example) yet it was 3 separate local color tables, when I originally wrote that section..
http://www.imagemagick.org/Usage/anim_basics/#color

This make things difficult as while usally you would like to use a common color map, you don't always want to do so (for example a slide show of very different images).

I hope to get Cristy to add a GIF format -define option to allow you to control this, but at this time no such control is known. Before I can do this I need to double check the source code for GIF output to see exactly what is going on.

I am hoping to re-write the GIF animation color optimization pages at some point to explain not just this quantization process and separate color tables but also the 'dither noise' problem. An example of this noise can be seen in the animation
http://www.imagemagick.org/Usage/distor ... _video.gif
(Fun example of swirl distortion contributed to IM examples by Florent Monnier)

This dithering noise now has a solution (after a major IM core programming effort on my part) using the new -ordered-dither 'color level' options.
http://www.imagemagick.org/Usage/quantize/#od_posterize

This is the recomended solution for 'video' to GIF Animation color handling.
I just having re-written the optimization parts in the animation sections yet.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
gydoesit

Re: How to use common colormap for animated gif at php?

Post by gydoesit »

Maybe your method can work under command line.But I tested by php5.2+php_magickwand_q16_st.dll in windows,
I found it still doesn't use comman color map,the file is big yet.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to use common colormap for animated gif at php?

Post by anthony »

Since I wrote this I have had the oppunity to work in the conversion of a short and small real-time video to GIF conversion...
http://www.imagemagick.org/Usage/video/

From this I have determined that IM does not currently automatically save using a common global color table, unless the images have a standard common colormap shared between them (using the -map color reduction operation).

The -colors quantization operator, as with most operators only reduces the colors of each image (frame) and not over the whole animation, and this is the default method used when saving to a GIF animation.

As to why my own 'moving hole' test animation ends up with a single global colortable... I have no idea, I designed it with multiple colors to try to force the use of local color maps, but obviously failed in my attempt.

If you realy want to force the use of a global color map, use the technique developed on the Animation Basics, Colormap optimization area
http://www.imagemagick.org/Usage/anim_b ... olortables
And again shown in the new "video to GIF" section.

Code: Select all

    convert moving_hole.gif \
            \( -clone 0--1 -background none -append  -colors 64 \
               -unique-colors -write mpr:colormap +delete \) \
            -map mpr:colormap      moving_hole_ctbls.gif
This appends all the frames together, then color quantizes it to a common 'best' colormap. This is then used to map all the colors of all the frames in the original animation to the same color tabel before saving.

WARNING: do not further modify the image data after this step or you will invalidate the optimization. Unless you want the modified frame to use a temporary seperate color map.

The video page uses a simpler version, as it does not have transparency to deal with. That will change if add transparency optimization features to IM, sometime in the future. A technique that should improve -ordered-dither performance.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply