PDA

View Full Version : Image Format Detection


1Unreal
03-09-2009, 04:58 PM
Im trying to detect the format of an image. But I get a parse error

<?php
$filename = 'http://static.php.net/www.php.net/images/php.gif';
$file = fopen($filename, 'rb');
$size = getimagesize($file);
switch ($size['mime']) {
case "IMAGETYPE_GIF":
echo "Image is a gif";
break;
case "IMAGETYPE_JPEG":
echo "Image is a jpeg";
break;
case "IMAGETYPE_PNG":
echo "Image is a png";
break;
?>

Lynne
03-09-2009, 05:14 PM
Where is this code located and what is the exact error you get and on what page?

1Unreal
03-09-2009, 05:36 PM
There's the code lol...and it doesn't matter I forgot the } on the end of the switch.

--------------- Added 1236625202 at 1236625202 ---------------

If anyone was curious about detecting image format this works quite nicely.

<?php
$filename = 'http://static.php.net/www.php.net/images/php.gif';
$size = getimagesize($filename);
switch ($size['mime']) {
case "image/gif":
echo "Image is a gif";
break;
case "image/jpeg":
echo "Image is a jpeg";
break;
case "image/png":
echo "Image is a png";
break;
}
?>