Recognizing File Formats

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
JasonStone

Recognizing File Formats

Post by JasonStone »

Hi

I have just a simple question I hope, but I couldn't find any answer on this question. If I use this command in PHP:

exec("convert filename.fileending -resize 200x200 filename.fileending);

but with different files (eg. .jpg / .gif / .png / .txt / .pdf / .doc / .xml..........)

Will ImageMagick actually only make changes on the typical image files (.jpg/.gif/.png...) or am I at risk that certain other filetypes get modified too? I am specially worried that weird things are happening, like that somebody uploads an Excel Sheet and it becomes corrupted.....

Do I need to check my filetype in PHP first or can I just let the command loose and ImageMagick ignores the non-image files?

Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Recognizing File Formats

Post by snibgo »

See http://www.imagemagick.org/Usage/files/#read

Convert stops if it can't read the image.

There is a chance, I suppose, that some random file might start with bytes that match an image type.
snibgo's IM pages: im.snibgo.com
JasonStone

Re: Recognizing File Formats

Post by JasonStone »

Thank you for the quick answer Snibgo.

Looks like a 99% goes it well solution. Mhmm, maybe I will build in a check before with getimagesize(), just to be sure.

Cheers!
Post Reply