How to identify animated image format.

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
teopau

How to identify animated image format.

Post by teopau »

I would like to know if it is possible to identify images with animation support.

I'm trying to display animated images, say gif files, using the image delay time and display multipage images using a fixed time, say 5 seconds.

I try not to use a "known" list of animated file format to do this to avoid having to add new ones when it is added to imagemagick.

If it is not possible, can someone please provide me a list of animated image file format.

Thanks in advance.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to identify animated image format.

Post by fmw42 »

What do you consider the characteristics of a file format that is as you call it "animated"?

There are many multi-frame formats, but not many can be displayed as an animation, as far as I know.

In what applications are you expecting such images to animate? How are you making them animate or switch frames? Are you doing the swapping yourself or are you expecting the application to do that for you via some built-in intelligence about the image format?

Please clarify, then perhaps the IM folks can give you an answer.
StephenP

Re: How to identify animated image format.

Post by StephenP »

As far as I know, the image depends on the file headers - so it depends on how the application you're planning on using interprets such files, I know that in PHP, for example, image loading functions go by header, not extension.

To determine if a file is animated, however, you can use the identify binary - if it is animated, then it should have multiple frames. (although there might be multi-frame, non-animated types :( ).
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to identify animated image format.

Post by anthony »

Basically you need to figure out what you take as being animated!
For example you say any image that is a
* GIF image file format
* has more than one image
* has disposals that are not 'none'
* has non-zero delays
* has the old netscale 'loop' attribute (which was not part of the original GIF format)

as being animated. What super or sub-set of thongs like this you take as being animated is up to the application.

For example I have a multi-image GIF file I use for dithering in one of my IM examples. It has no delays, timings or disposals, and was NEVER meant to be used as an animation!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to identify animated image format.

Post by fmw42 »

Anthony,

I think he is also trying to find out if there are other image formats like tif that allow multi-frames but also can be animated upon display in one way or another. I only know about Gif, but perhaps there are others.

Fred
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to identify animated image format.

Post by anthony »

GIF was turned into an animated format by Netscape. It is limited in what it can do, and is usually best with small cartoon-like animations. Actually it is perfect for desktop animations, and sic advertising. :?

TIF is usually not regarded as an animated format as it has no animation controls that I know of, at least not that is standard. More commonly multiple images are either exploded layers of some complex image, or separate pages of a document, rather than some type of animation.

MNG is a simple animated format for PNG whcih is suposed to be simular to GIF but I have not had much experience with it.

The others MPEG, AVI, etc are movie formats designed more with
longer movies in mind than looping animations. AVI itself is not what I call a 'format' as more of a meta-format. That is a format of hundreds of different formats or 'codecs'.

Now this is NOT to say you can use other image formats for animations. You can for example animate the IM format MIFF, but also directly animate PNG and JPEG which was saved as a ordered list of frames. It is just not very nice, nor very standard practice, except for example animating an archive of camera images.

Back to the original question.

Just about anything can be an animation in a specific circumstance so the question remains... What do you want to consider to be an animation? That is... What limits do you want to set?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
teopau

Re: How to identify animated image format.

Post by teopau »

Thanks for all your reply.

First animated format to me would be a format that is commonly use or designed for animation, in this case I would need know the list of all supported format, which I'm trying to avoid. Unless of course the list of format is quite stable for a few years down or if it is the best way.

In any case, I'm sure I would need the list to handle special cases. Know any other format besides gif and mng?

Besides multipage, disposals, delays and loop, is there any other attributes/properties that I need to consider when trying to determine animated formats.

I think the main problems is that there is no way the determine if delay is zero or "undefined", as I would think that in animation as timing is what make an animation animation, rite? What about other animation formats, is delay used?

I notice that for avi the delay is not set. How do I know the frame rate.

My application will do all the display timing, but as a far as formats that require some processing to display, e.g. gif, I would use the built-in function, e.g. MagickCoalesceImages (only for gif?), to do it. Is there any other function that I should be aware of?

I'm using is in a slideshow like application where animated images will be displayed as intended by the author and multipages images be displayed on a user defined delay.

Thanks Again.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to identify animated image format.

Post by fmw42 »

You can find out the delay in each frame of an animated gif and likely any other multiframe format using:

First create an animation:
convert -delay 100 rose: -delay 50 rose: -delay 25 rose: -loop 0 rose_animation.gif

Now find out its delay in ticks (along with other information using a custom identify:
info="%f[%s] %m %Tticks %wx%h %P%O %r %z-bit %Q%%qual %bbytes\n"
identify -format "$info" rose_animation.gif

animation.gif[0] GIF 100ticks 70x46 70x46+0+0 8-bit PseudoClassRGB 256c 0%qual 10878bytes
animation.gif[1] GIF 50ticks 70x46 70x46+0+0 8-bit PseudoClassRGB 256c 0%qual 10878bytes
animation.gif[2] GIF 25ticks 70x46 70x46+0+0 8-bit PseudoClassRGB 256c 0%qual 10878bytes

Note %T returns ticks of delay.

You can find out if the image is set to -loop 0 and the delay by using the -verbose info:
identify -verbose rose_animation.gif

The following information can be found for each frame in the verbose info:

Dispose: Undefined
Delay: 100x100
Iterations: 0
Scene: 0 of 3


So the delay on the first frame (frame 0) was 100 and the -loop was set to 0 (via the iterations)
Post Reply