Page 1 of 1

Recognizing File Formats

Posted: 2010-05-20T01:56:13-07:00
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!

Re: Recognizing File Formats

Posted: 2010-05-20T02:24:13-07:00
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.

Re: Recognizing File Formats

Posted: 2010-05-20T04:08:49-07:00
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!