August 10, 2011

getImgSrc a handy function in PHP image manipulation for php developers

function getImgSrc($fileName)
{
$mime_type = getimagesize($fileName);

//print_r($mime_type);

switch($mime_type[‘mime’])
{
case ‘image/png’:
$src = imagecreatefrompng($fileName);
break;
case ‘image/gif’:
$src = imagecreatefromgif($fileName);
break;
case ‘image/jpeg’:
$src = imagecreatefromjpeg($fileName);
break;
case ‘image/wbmp’:
$src = imagecreatefromwbmp($fileName);
break;

}

return $src;
}

Last updated: March 19, 2014