I did some tweaking on the code. Here is the updated version:
$fd = fopen($filename,"r");
$image_string = file_get_contents($filename);
$img_info = @getimagesize($filename);
$width = $img_info[0];
$height = $img_info[1];
fclose($fd);
$photo = imagecreatefromstring($image_string);
The error I get when $filename is a URL is this:
Failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
Any help would be greatly appreciated!!!