PHP图片判断大小压缩代码
标签搜索
侧边栏壁纸
  • 累计撰写 3 篇文章
  • 累计收到 0 条评论
PHP

PHP图片判断大小压缩代码

admin
2024-11-24 / 0 评论 / 8 阅读 / 正在检测是否收录...
        //图片压缩开始了
        if($fileInfo['type']=='image/jpeg' || $fileInfo['type']=='image/png' || $fileInfo['type']=='image/gif' || $fileInfo['type']=='image/jpg' || $fileInfo['type']=='image/webp')
        {
             if($fileInfo['type']=='image/png' || $fileInfo['type']=='image/gif'){
                 $this->ImageToJPG($img_path, $img_path, $imagewidth , $imageheight);
             }
            require_once VENDOR_PATH.'topthink/think_image.php';
            $image = \think\Image::open($img_path);
            if($imagewidth < 720){
                if($imagewidth > $imageheight){
                    $image->thumb($imagewidth, $imageheight)->save($img_path);
                    //file_put_contents(ROOT_PATH.'/1.txt', print_r($imagewidth, true));
                }else{
                    $image->thumb($imagewidth, $imagewidth, 3)->save($img_path);
                    $imageheight = $imagewidth;
                }
            }else{
                //file_put_contents(ROOT_PATH.'/kiqik.txt', print_r('kiqik', true));
                if($imagewidth > $imageheight){
                    $zoom = $imagewidth / 720;
                    $image->thumb(720, $imageheight/$zoom)->save($img_path);
                    $imageheight = $imageheight/$zoom;
                    $imagewidth = 720;
                }else{
                    $image->thumb(720, 720, 3)->save($img_path);
                    $imagewidth = 720;
                    $imageheight = 720;
                }
            }
            clearstatcache();
            $fileInfo['size'] = filesize($img_path);
            
        }

        //图片压缩结束了
0

评论 (0)

取消