You need to check the file type - the best way is to check the mime type if you can, then you can do a switch and utilize the other image creation functions in GD lib such as imagecreatefromgif() and imagecreatefrompng() etc:
switch($mime_type) {
case 'image/jpeg':
case 'image/jpg':
$img = imagecreatefromjpeg($filename);
break;
case 'image/png':
$img = imagecreatefrompng($filename);
break;
case 'image/gif':
$img = imagecreatefromgif($filename);
break;
}
Another option is for you to grab the image's data into a string and use imagecreatefromstring() to create an image handle from raw data:
$filename = 'http://yoursite.com/yourlogo.jpg';
$img = imagecreatefromstring(file_get_contents($filename));
From the manual: These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2.