Help with curl

I’ll admit, I barely know anything about PHP, but I’m trying to convert some code from using fopen_url to using curl.

This chunk of code is what’s throwing errors for me:

[code]$img_res = imagecreatetruecolor(300, 300); //temp image used for resizing that will be deleted later

switch ($ext) {

case 'png':
	$img[$i]= imagecreatefrompng($img_url);

case 'jpg':
	$img[$i]= imagecreatefromjpeg($img_url);

case 'gif':
	$img[$i]= imagecreatefromgif($img_url);


I’ve been Googling around but haven’t really found much that I can use. Any tips?

The imagecreate functions require a filepath as input, so you would need to curl the remote image to a local file and then feed that local file into the function.

You could try something like this.

$local_image_filepath = ‘google.png’;
$remote_image_url = ‘’;

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $remote_image_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
$image_source_code = curl_exec($ch);

file_put_contents($local_image_filepath, $image_source_code);

Then you would just use the $local_image_filepath as the parameter in the imagecreate functions.