public function img() { //实例化图像处理类,默认为GD库 $image = new Image(); //加载一张预处理的图片 $image->open('./Public/images/1.jpg'); //上面两句,可以用一句话包含 //$image = new Image(Image::IMAGE_GD, './Public/images/1.jpg'); //获取图片信息 $arr['width'] = $image->width(); $arr['height'] = $image->height(); $arr['type'] = $image->type(); $arr['mime'] = $image->mime(); $arr['size'] = $image->size(); //裁剪图片,高400,宽400 $image->crop(400, 400)->save('./Public/images/1.jpg'); $image->open('./Public/images/2.jpg'); $image->thumb(300, 300, Image::IMAGE_THUMB_CENTER)->save('./Public/images/2.jpg'); //在图片右下角添加水印并生成 $image->open('./Public/images/3.jpg'); $image->water('./Public/images/logo.png')->save('./Public/images/3.jpg'); echo '<pre>' . print_r($arr, 1) . '</pre>'; }
public function imginfo() { $path = './Public/images/demo.jpg'; $image = new Image(Image::IMAGE_GD, $path); dump(['width' => $image->width(), 'height' => $image->height(), 'mime' => $image->mime(), 'type' => $image->type()]); }