压缩图片

admin6个月前Laravel279
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 tosend($openid, $title, $content, $time, $aid){    $tokens = $thi...

两个经纬度之间的距离

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

excel 导出

header("Content-Type: application/vnd.ms-excel; name='excel'"); header("Content-Disposition:atta...

编辑用户信息

*/public function useredit(){    $avatar = request()->input('avatar');   &...

忘记密码

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

微信退款v3

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