//利用远程jpg图片创建新jpg图片
function resizejpg($imgsrc,$imgwidth,$imgheight,$filepath)
{
$arr = getimagesize($imgsrc);
$imgWidth = $imgwidth;
$imgHeight = $imgheight;
$imgsrc = imagecreatefromjpeg($imgsrc);
$image = imagecreatetruecolor($imgWidth, $imgHeight); //创建一个彩色的底图
imagecopyresampled($image, $imgsrc, 0, 0, 0, 0,$imgWidth,$imgHeight,$arr[0], $arr[1]);
if(file_exists($filepath)){
unlink($filepath);
imagejpeg($image,$filepath);
}else{
imagejpeg($image,$filepath);
}
function resizejpg($imgsrc,$imgwidth,$imgheight,$filepath)
{
$arr = getimagesize($imgsrc);
$imgWidth = $imgwidth;
$imgHeight = $imgheight;
$imgsrc = imagecreatefromjpeg($imgsrc);
$image = imagecreatetruecolor($imgWidth, $imgHeight); //创建一个彩色的底图
imagecopyresampled($image, $imgsrc, 0, 0, 0, 0,$imgWidth,$imgHeight,$arr[0], $arr[1]);
if(file_exists($filepath)){
unlink($filepath);
imagejpeg($image,$filepath);
}else{
imagejpeg($image,$filepath);
}
}
$imgsrc="http://domain/2.jpg";
$filepath = "/a/1.jpg";
resizejpg($imgsrc,100,50,$filepath);
exit;