I have a problem, I need to take image from distant url. I use curl, then try to use a resize function. this is the code:
Code:
$ch = curl_init($url);
$fp = fopen($source_file, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);

function resize($file_input, $file_output, $w_o, $h_o, $percent = false) {
	list($w_i, $h_i, $type) = getimagesize($file_input);
	if (!$w_i || !$h_i) {
		echo 'Can't get width and length';
		return;
    }
    $types = array('','gif','jpeg','png', 'GIF', 'JPEG', 'PNG');
    $ext = $types[$type];
    if ($ext) {
    	$func = 'imagecreatefrom'.$ext;
    	$img = $func($file_input);
    } else {
    	echo 'incorrect file format';
		return;
    }
	if ($percent) {
		$w_o *= $w_i / 100;
		$h_o *= $h_i / 100;
	}
	if (!$h_o) $h_o = $w_o/($w_i/$h_i);
	if (!$w_o) $w_o = $h_o/($h_i/$w_i);
	$img_o = imagecreatetruecolor($w_o, $h_o);
	imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
	if ($type == 2) {
		return imagejpeg($img_o,$file_output,100);
				imagedestroy($img_o);

	} else {
		$func = 'image'.$ext;
		return $func($img_o,$file_output);
	}
}


resize($source_file, $out_s_file, 200, 200);
but there is some problem with it, like this Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file. And this is all about jpg file: imagecreatefromjpeg() [function.imagecreatefromjpeg]: './images/dab59780be1eed54e39deb2a338c2ced.jpg' is not a valid JPEG

the same problem with png. gif image resize ok, but there is not a dinamic gif image anymore. What I do wrong?