A: 

In response to your new questions:

1) I am using imagejpeg($image, null, 100); and I am wondering, should I be using something else? DOes it require the source image to be a jpg or will it work wiht any image? I need to allow the main types (jpg, jpeg, gif, png)

Well, php.net says, "imagejpeg() creates a JPEG file from the given image". But the important part is this, "An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().". And your using "imagecreatefromstring() returns an image identifier representing the image obtained from the given data . These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2." So, that should be ok.

2) same as above question but for when showing the image on screen I have header set to this: header('Content-Type: image/jpeg'); should it not be jpg for other type of images?

The header should be of type jpg - If that's the file type, then you're correct.

3) Is there a way that I can make sure that the source URL passed in is an actual image and do whatever I want if it is not a image, like show my own error or do my own code once it detect that the URL is not a valid image url

Yeah - Instead of doing:

$image = ImageCreateFromString(file_get_contents($url));

You could do:

$image = imagecreatefromjpeg($url);
if (!$image) echo "error"; 

imagecreatefromjpeg() returns an image identifier representing the image obtained from the given filename.

But really, what you have is fine.


Does it display the error message

    echo 'The URL was not passed into our funtion';

Or nothing at all?

If the error messaging is being displayed, possible the check === is failing:

An image resource will be returned on success. FALSE is returned if the image type is unsupported, the data is not in a recognised format, or the image is corrupt and cannot be loaded.

Also, do you have error logging maxed out on your development server? That way you can see any possible warnings being thrown?

Mr-sk
I have error_reporting(E_ALL) set. I got it working somewhat now, I have updated my question though with some other questions about this if you can help any?
jasondavis
Hi thanks for the post, It is working the way I have it, just the image does not look good, the background is showing up as black, I think it was a transparent png file that I tried from twitter URL
jasondavis