{"id":67323,"date":"2006-05-15T08:55:00","date_gmt":"2006-05-15T08:55:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/05\/15\/how-can-i-tell-whether-a-gif-file-is-a-regular-picture-file-or-an-animated-picture-file\/"},"modified":"2006-05-15T08:55:00","modified_gmt":"2006-05-15T08:55:00","slug":"how-can-i-tell-whether-a-gif-file-is-a-regular-picture-file-or-an-animated-picture-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-tell-whether-a-gif-file-is-a-regular-picture-file-or-an-animated-picture-file\/","title":{"rendered":"How Can I Tell Whether a .GIF File is a Regular Picture File or an Animated Picture File?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! I have a silly question for you: how can I tell whether a .GIF file is a regular old picture file or an animated picture file?<BR><BR>&#8212; WW<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, WW. To begin with, there\u2019s no such thing as a silly question. We\u2019ve always believed that &#8211; well, come to think of it, last summer a neighbor\u2019s smoldering firework caught one of the Scripting Guys\u2019 garages on fire. As he stood there in the middle of the night, talking to the fire chief and watching the fire fighters put out the fire, another neighbor rushed up to him and said, \u201cOh, my gosh: did you know that your house is on fire!?!\u201d<\/P>\n<P>So, in retrospect, maybe there <I>is<\/I> such a thing as a silly question. We stand corrected.<\/P>\n<P>To tell you the truth, WW, we didn\u2019t find your question silly. However, we did assume that there was no possible way to retrieve that information using a script. After all, we can\u2019t manage our wireless settings using a script; what do you suppose the odds are that we could use a script to determine whether or not a .GIF file was animated?<\/P>\n<P>As it turns out, those odds are surprisingly good:<\/P><PRE class=\"codeSample\">Set objImage = WScript.CreateObject(&#8220;WIA.ImageFile&#8221;)\nobjImage.LoadFile(&#8220;c:\\scripts\\dr_scripto_anim.gif&#8221;)<\/p>\n<p>If objImage.IsAnimated Then\n    Wscript.Echo &#8220;This is an animated image.&#8221;\nElse\n    Wscript.Echo &#8220;This is not an animated image.&#8221;\nEnd if\n<\/PRE>\n<P>The trick here is to use the Windows Image Acquisition (WIA) 2.0 library. Now, it\u2019s possible that you don\u2019t have WIA installed on your machine; if that\u2019s the case you can download everything you need from <A href=\"http:\/\/null\/downloads\/details.aspx?FamilyID=a332a77a-01b8-4de6-91c2-b7ea32537e29&amp;DisplayLang=en\" target=\"_blank\"><B>here<\/B><\/A>. Note that, for some reason, you need to download the entire WIA SDK (which is just a 520KB .zip file). Download the SDK and extract all the files to a folder of your choice, then use Regsvr32.exe to register the Wiaaut DLL file:<\/P>\n<P>regsvr32 wiaaut.dll<\/P>\n<TABLE id=\"EJD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. How would you <I>know<\/I> that you don\u2019t have WIA 2.0 installed on your computer? One easy way to tell is to try running the script. If it fails with a \u201ccan\u2019t create object\u201d error then you don\u2019t have WIA 2.0 installed.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Once you have WIA installed the rest is easy. We start out by creating an instance of the <B>WIA.ImageFile<\/B> object, then use the <B>LoadFile<\/B> method to bind to the file we want to check. (In this case, that\u2019s C:\\Scripts\\Dr_Scripto_Anim.gif.) We then check the value of the <B>IsAnimated<\/B> property. If IsAnimated is True then we\u2019re dealing with an animated picture file. If IsAnimated is False then our picture file is <I>not<\/I> animated. <\/P>\n<P>Like we said, we had no idea you could even <I>do<\/I> this, let alone know that it would be this easy.<\/P>\n<P>To be honest, we haven\u2019t played around with the WIA scripting library very much. It looks interesting, though: after all, if you have the right equipment, you can use scripts to control such things as scanners and Web cameras. If that piques your interest, take a look at the <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/wiaaut\/wia\/wiax\/overviews\/startpagewiaaut.asp\" target=\"_blank\"><B>Windows Image Acquisition SDK<\/B><\/A> on MSDN.<\/P>\n<P>Of course, once we got started checking to see if our picture files were animated, well, it was pretty hard to stop. With that in mind we thought we\u2019d toss in a bonus script, one that checks all the files in a folder and reports back any that happen to be animated picture files. We won\u2019t discuss this script in any great detail, but we will tell you what it does:<\/P>\n<TABLE border=\"0\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>It uses the FileSystemObject to bind to the folder C:\\Scripts (using the <B>GetFolder<\/B> method).<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>It creates an object reference named <B>colFiles<\/B> that contains all the files found in C:\\Scripts.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>For each file in the folder it tries loading the file using the LoadFile method. As you might expect, LoadFile can only load image files; it can\u2019t load, say, Word documents or executable files. Therefore each time the script calls LoadFile it checks the value of the VBScript <B>Err<\/B> object. If Err is equal to 0 that means the file loaded successfully; if Err is anything <I>but<\/I> 0 that means the file could be loaded.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>For each file successfully loaded the script checks the value of the IsAnimated property; it then echoes back the file name if IsAnimated is True. If a file cannot be loaded the script simply skips this step altogether.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>The script resets the Err object back to 0, then loops around and repeats the process with the next file in the collection.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<P>Here\u2019s what the code looks like:<\/P><PRE class=\"codeSample\">On Error Resume Next<\/p>\n<p>Set objImage = WScript.CreateObject(&#8220;WIA.ImageFile&#8221;)<\/p>\n<p>Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)\nSet objFolder = objFSO.GetFolder(&#8220;C:\\Scripts&#8221;)<\/p>\n<p>Set colFiles = objFolder.Files<\/p>\n<p>For Each objFile in colFiles\n    strFile = &#8220;C:\\Scripts\\&#8221; &amp; objFile.Name\n    objImage.LoadFile(strFile)\n    If Err = 0 Then\n        If objImage.IsAnimated Then\n            Wscript.Echo objFile.Name\n        End If\n    End If\n    Err.Clear\nNext\n<\/PRE>\n<P>And, in case you\u2019re wondering, yes, this Scripting Guy <I>was<\/I> aware that his house was on fire. Painfully aware, as they say.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I have a silly question for you: how can I tell whether a .GIF file is a regular old picture file or an animated picture file?&#8212; WW Hey, WW. To begin with, there\u2019s no such thing as a silly question. We\u2019ve always believed that &#8211; well, come to think of it, last [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[122,123,3,5],"class_list":["post-67323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-graphics","tag-multimedia","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I have a silly question for you: how can I tell whether a .GIF file is a regular old picture file or an animated picture file?&#8212; WW Hey, WW. To begin with, there\u2019s no such thing as a silly question. We\u2019ve always believed that &#8211; well, come to think of it, last [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=67323"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67323\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=67323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}