Search code examples
asp.netanimated-giffile-rename

ASP.NET: How to check if an image is a GIF, specifically images with changed extensions


I've taken over work for the custom forums that a previous developer created at my job, and came across a minor bug. We don't allow animated GIFs as avatars in the forums. However, if someone were to take an animated GIF, rename it to imagename.jpeg, and then upload it, the forums will show the image as being animated.

It's a very odd bug as I didn't even think it played the animation if the extension wasn't .gif.

So my question is: Is there a way to check (in .NET 2.0) if an image is an animated gif, even if the extension isn't?

Bara


Solution

  • You could open the file and analyze its header to see if it is a GIF. According to http://www.onicos.com/staff/iz/formats/gif.html, the first 3 bytes of the header should be "GIF".