Page 1 of 1

Detecting file format?

Posted: 2007-01-07T10:34:43-07:00
by webmaster33
Is it possible to detect the format of a file using ImageMagick?


I would need to detect at least the following formats:
- common image formats (jpg, gif, bmp, tif, tga, etc...)
- common video formats (avi, mpg, etc...)
- common sound formats (wav, mp3, etc...)
- common text/office formats (txt, html, word, excel, access, powerpoint, etc...)

Posted: 2007-01-07T16:33:48-07:00
by anthony
Sounds more like the UNIX "file" command to me :-)

Posted: 2007-01-07T18:21:44-07:00
by webmaster33
anthony wrote: Sounds more like the UNIX "file" command to me :-)


Well, I know about the "file" command, but would be needed a platform independent solution, as I develop my website under Windows. The "file" command uses a magic file, where the file footprints are listed. This could be also used by ImageMagick, too.

ImageMagick is platform independent, and such feature would make image detection much easier. And if images are detected, why not detect other file formats, too, so I can tell the visitor, what is wrong with his uploaded file?

I have a website, where users are uploading images. Sometimes they are also uploading files, which are not images at all or they are not supported by ImageMagick. This is why I would welcome a feature, which detects the format of the file. This feature should be also implemented into Perl API, because I use Perl language.


Developers?
Would you consider implementing such feature?

Posted: 2007-01-07T18:33:52-07:00
by anthony
Unix uses such a file too, with the linux version much more advanced in entries.
However this "/etc/magic" is commonly published, so I am supprised a windows version whcih can use the UNIX 'magic' is not generally available.

For fast file type determination it is a lot faster than IM, as Im is restricted to just formats it knows about and often needs to read in to identify. Mind you for images IM identify can get you a lot more info, like Exif Metadata, but of course the price is speed.

Your choice.

Posted: 2007-01-07T18:42:37-07:00
by webmaster33
anthony wrote: For fast file type determination it is a lot faster than IM, as Im is restricted to just formats it knows about and often needs to read in to identify. Mind you for images IM identify can get you a lot more info, like Exif Metadata, but of course the price is speed.


Not faster, as Perl needs to use `backtick` operator to spawn perl interpreter, start the external command "file", then get its output. That's why using the ImageMagick Perl API is faster than using the backtick Perl operator.

IMHO, would be logical feature, to add a command which just quickly identify file type, using a short magic string.

Also note, ImageMagick has also the word magic in his name so this also adds a point to implement this feature :)

Posted: 2007-01-07T19:03:13-07:00
by magick
The Wizards Toolkit has a mime-detection method but ImageMagick does not. See http://www.wizards-toolkit.org/

Posted: 2007-01-07T19:25:17-07:00
by webmaster33
magick wrote: The Wizards Toolkit has a mime-detection method but ImageMagick does not. See http://www.wizards-toolkit.org/

Yeah, thanks!
However it seems the Wizard's Toolkit doesn't have a Perl interface.

Posted: 2007-01-07T19:35:25-07:00
by magick
Use CPAN. I'm sure there is a mime detection method available for Perl.

Posted: 2007-01-07T19:46:54-07:00
by webmaster33
Thanks, will try it.