压缩图片

admin5个月前Laravel219
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 setpass(){    $mobile = request()->input('mobile');   &nbs...

php 优化

使用 gc_collect_cycles() 强制进行垃圾回收 PHP 的垃圾回收机制会自动释放不再使用的变量所占用的内存。然而,在某些情况下,尤其是在长时间运行的脚本(如 CLI...

验证手机号

public function phone($phone){    $pat = '/'        . '^13...

批量处理数据

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

生成唯一的订单号

public function get_order_sn() {     return date('Ymd') ...

laravel 加cache锁

use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Cache; $lock = Ca...