garlics
216 天前
之前封装了一个这个方法,你把里面的变量替换成你的就可以了。
```
$info = getimagesize($url);
$fun = "imagecreatefrom{$record->ext}";
$imgInfo = $fun($url); //1.由文件或 URL 创建一个新图象。如:imagecreatefrompng ( string $filename )
$mime = $info['mime'];
header('Content-Type:' . $mime);
if ($width && $height) {
$newImage = imagecreatetruecolor($width, $height);
//生成最后的图片
imagecopyresampled($newImage, $imgInfo, 0, 0, 0, 0, $width, $height, $info[0], $info[1]);
$imgInfo = $newImage;
}
$quality = 75;
if ($record->ext == 'png') $quality = -1; //输出质量,JPEG 格式(0-100),PNG 格式(0-9)
$getImgInfo = "image{$record->ext}";
$getImgInfo($imgInfo, null, $quality); //2.将图像输出到浏览器或文件。如: imagepng ( resource $image )
imagedestroy($imgInfo);
```