ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
具体的composer安装方法在本站可以搜索"composer", 这里要说的是安装yii2-imagine composer中国镜像, apache和php.ini打开ssl是必须的, 我看到yiichina上有个安装yii2-imagine的教程是,用的下载zip包,又是改这个又是改那个,虽然我比较喜欢下载,但是现在流行composer,没办法,得跟节奏 安装 1.DOS命令切换到项目目录, 然后直接执行下面命令 composer require --prefer-dist yiisoft/yii2-imagine 执行命令如下: You are running Composer with SSL/TLS protection disabled. Using version ^2.1 for yiisoft/yii2-imagine ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) - Installing imagine/imagine (v0.6.3) Downloading: 100% - Installing yiisoft/yii2-imagine (2.1.0) Downloading: 100% imagine/imagine suggests installing ext-imagick (to use the Imagick implementati on) imagine/imagine suggests installing ext-gmagick (to use the Gmagick implementati on) Writing lock file Generating autoload files 2.查看是否安装成功, 安装了两个目录分别是 vendor/imagine vendor/yiisoft/yii2-imagine 使用 引入 use yii\imagine\Image; 实例化 $imagine = new Image(); 使用方法 //压缩 Image::thumbnail('@webroot/img/test-image.jpg', 120, 120)->save(Yii::getAlias('@webroot/img/thumb-test-image.jpg'), ['quality' => 100]); echo Yii::getAlias('@webroot/img/thumb-test-image.jpg'); //参数说明: $filename 文件的路径 $width 缩略图的宽 $height 缩略图的高 $mode 模式(默认THUMBNAIL_OUTBOUN) \Imagine\Image\ManipulatorInterface::THUMBNAIL_OUTBOUN 裁剪模式 \Imagine\Image\ManipulatorInterface::THUMBNAIL_INSET 填充模式 //剪切 $result = Image::crop('@webroot/img/test-image.jpg', 200, 200,[100,100])->save(Yii::getAlias('@webroot/img/thumb-test-crop.jpg')); //参数说明: $filename 文件的路径 $width 裁剪的宽度 $height 裁剪的高度 $start 裁剪的x,y 点 //旋转 Image::frame('@webroot/img/test-image.jpg', 5, '666', 0)->rotate(-8)->save(Yii::getAlias('@webroot/img/thumb-test-frame.jpg'), ['quality' => 100]); //水印 Image::watermark('@webroot/img/test-image.jpg', '@webroot/img/watermark.jpg', [10,10])->save(Yii::getAlias('@webroot/img/thumb-test-watermark.jpg'), ['quality' => 100]); //参数说明: $filename 文件的路径 $watermarkFilename 水印图片 $start 裁剪点(x,y) //文字水印 Image::text('@webroot/img/test-image.jpg', 'hello world', '@webroot/img/symbol.ttf',[100,100],['color'=>'000000','size'=>50])->save(Yii::getAlias('@webroot/img/thumb-test-text.jpg'), ['quality' => 100]); 各处理方法里的test-image.jpg为被处理的图片, thumb-test-text.jpg为处理后保存的图片,quality不用说了,是质量, 保存图片跟处理图片路径一样,比如水印,就是覆盖原图