压缩图片

admin11个月前Laravel463
public static function size($id, $img)
{ try { list($width, $height, $img_type, $attr) = @getimagesize($img);
        $imageinfo = array('width' => $width, 'height' => $height, 'type' => image_type_to_extension($img_type, false), 'attr' => $attr); if ($imageinfo) {
            $fun = "imagecreatefrom" . $imageinfo['type'];
            $image = $fun($img);
            $percent = '0.5';
            $new_width = $imageinfo['width'] * $percent;
            $new_height = $imageinfo['height'] * $percent;
            $image_thump = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_thump, $image, 0, 0, 0, 0, $new_width, $new_height, $imageinfo['width'], $imageinfo['height']); imagedestroy($image);
            $image = $image_thump;
            $func = 'image' . $imageinfo['type'];
            $title = str_replace('image', 'img_cory', $img);
            $func($image, $title); Db::table('product')->where(array('id' => $id))->update(['image' => $title]);
        }
    } catch (Exception $e) { echo $id;
    }
}

相关文章

百度浏览器中视频悬浮

  <video class="html5-video"                poster=...

两个经纬度之间的距离

    public function haversineGreatCircleDistance($latitude1, $longitude1, $latitude2, $lon...

抖音小程序码

public function dyqrcode($uid){    $url = "https://open.douyin.com/api/apps/v1/qrcode...

下载文件

public function img_url() { $id = request()->param('id', 1122); $info = Db::name('...

解密微信绑定的手机号

public function mobile() { $code = request()->input('code'); if (!$code) { return $this-&...

忘记密码

publicfunction forget(){    $phone = request()->input('phone');    $c...