最新消息:

PHP 自动压缩大于720宽度图片

开发 admin 1315浏览 0评论
            /* 对图像文件进行严格检测 */
            $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宽度图片

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址