压缩图片

admin9个月前Laravel413
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;
    }
}

相关文章

微信退款v3

/** * 微信 退款 操作 */ public function refund($out_trade_no, $refund_money) { $time = time();...

发送公众号信息

* 发送消息 */public function tosend($openid, $title, $content, $time, $aid){    $tokens = $thi...

生成二维码

public function qrcode($uid){    require_once base_path() . '/public/phpqrcode/phpqrco...

过滤违禁词

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

关注公众号并登录

/* * 服务端生成带唯一标识二维码并将唯一标识返回给前端 */ public function wx_code() { $scene_str = $this->get_...

手机号替换

 $vv = substr_replace($vv, '****', 3, 4) ....