php 利用远程图片创建新图片完善(jpg,png,gif)

来源:互联网 发布:淘宝隐形牙套有用吗 编辑:程序博客网 时间:2024/06/08 09:14
function resizeimage($imgsrc,$imgwidth,$imgheight,$filepath)
{
$arr = getimagesize($imgsrc);
$imgWidth = $imgwidth;
$imgHeight = $imgheight;
$mime = explode('/',$arr['mime']);
$ext = $mime[1];
$func = 'imagecreatefrom'.$ext;
$imgsrc = $func($imgsrc);
$image = imagecreatetruecolor($imgWidth, $imgHeight); //创建一个彩色的底图
imagecopyresampled($image, $imgsrc, 0, 0, 0, 0,$imgWidth,$imgHeight,$arr[0], $arr[1]);
$func_c = 'image'.$ext;
if(file_exists($filepath)){
unlink($filepath);
$func_c($image,$filepath);
}else{
$func_c($image,$filepath);
}
}
$imgsrc="http://domain/99_2.jpg";
//$imgsrc="http://domain/images/2.gif";
//$imgsrc="http://domain/images/imgtest/images/jianlong_bg.png";


$imgext = getimagesize($imgsrc);
if($imgext[2]==1){
$ext = '.gif';
}else if($imgext[2]==3){
$ext = '.png';
}else{
$ext = '.jpg';
}
$filepath = "/a/1".$ext;
resizeimage($imgsrc,100,50,$filepath);
exit;
0 0
原创粉丝点击