压缩图片

admin1年前Laravel532
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;
    }
}

相关文章

下载文件

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

接口返回处理

public function __construct()    {        $action = request()->rout...

批量处理数据

   public function index44()    {        $domain = request(...

用户注册账号

public function register(){    $mobile = request()->input('mobile');   &nb...

抖音小程序码

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

过滤违禁词

/** * 内容验证 */public function check($content){    $count = 0; //违规词的个数    $list =...