生成图片的PHP代码如下://generate.php
$src =  'photo/'.$photo_name;
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

imagecopyresampled($dst_r,$img_r,0,0,(int)$_GET['cropx'],(int)$_GET['cropy'],
    $targ_w,$targ_h,(int)$_GET['cropwidth'],(int)$_GET['cropheight']);

header('Content-type: image/jpeg');
imagejpeg($dst_r, null, $jpeg_quality);然后insert.php//获取远程图片函数
function GrabImage($url,$filename="") { 
if($url==""):return false;endif; 
if($filename=="") { 
$ext=strrchr($url,"."); 
if($ext!=".gif" && $ext!=".jpg"):return false;endif; 
$filename=date("dMYHis").$ext; 

ob_start(); 
readfile($url); 
$img = ob_get_contents(); 
ob_end_clean(); 
$size = strlen($img); 
$fp2=@fopen($filename, "a"); 
fwrite($fp2,$img); 
fclose($fp2); 
return $filename; 
}
$url = 'http://localhost/generate.php?action=generatePic&cropx=.....(参数略)';
$imgName = GrabImage($url);
$img = addslashes(fread(fopen($imgName,"r"),filesize($imgName)));
$link = mysql_connect('localhost','mydb','123456') or die(mysql_error());
mysql_select_db('photo',$link) or die ('Can\'t use foo : ' . mysql_error());
$qty = mysql_query("update `customers` set customers_photo='". $img ."' where customers_id=55",$link);如上代码,插入图片到数据库后,数据库里存入的是一大堆html代码。 
但把$url改成一个实实在在的图片地址,如http://avatar.profile.csdn.net/3/6/F/2_jimx102.jpg,就可以成功插入并且把$url的值:http://localhost/generate.php?action=generatePic&cropx=.....(参数略) 输入浏览器是可以输出图片的