Automatic image format detection in PHP

MPX picture MPX · Oct 10, 2008 · Viewed 17.8k times · Source

I am looking for a way to take a user uploaded image that is currently put in a temporary location ex: /tmp/jkhjkh78 and create a php image from it, autodetecting the format.

Is there a more clever way to do this than a bunch of try/catching with imagefromjpeg, imagefrompng, etc?

Answer

Neall picture Neall · Oct 10, 2008

This is one of the functions of getimagesize. They probably should have called it "getimageinfo", but that's PHP for you.