/* 对图像文件进行严格检测 */
$ext = strtolower($file['ext']);
if (in_array($ext, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'])) {
$imginfo = getimagesize($file['tmp_name']);
if (empty($imginfo) || ('gif' == $ext && empty($imginfo['bits']))) {
$this->error = '非法图像文件!';
continue;
}
if ($imginfo[0] > 720) {
$fun = "imagecreatefrom".$ext;
$image_old = $fun($file['tmp_name']);
$new_width = 720;
$new_height = $imginfo[1] * 720 / $imginfo[0];
$image_thump = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($image_thump,$image_old,0,0,0,0,$new_width,$new_height,$imginfo[0],$imginfo[1]);
imagedestroy($image_old);
$funcs = "image".$ext;
$funcs($image_thump,$file['tmp_name']);
}
}
转载请注明:莫晓寒 » PHP 自动压缩大于720宽度图片