yii2-imagine的使用

<?php
/**
 * 图片常用处理
 *
 * 需要 yii/yii2-imagine 的支持
 * php composer.phar require --prefer-dist yiisoft/yii2-imagine
 *
 * 文件上传参考文档编写文件上传类
 * @link http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html
 *
 * @author yikai.shao
 */
namespace appcontrollers;

use ImagineImageManipulatorInterface;
use yiiimagineImage;

class ImageController extends yiiwebController
{
    //裁剪
    public function actionCrop()
    {
        Image::crop(‘11.jpg‘, 1000, 1000,[500,500])
        ->save(‘11_crop.jpg‘);
    }

//旋转 public function actionRotate() { Image::frame(‘11.jpg‘, 5, ‘666‘, 0) ->rotate(-8) ->save(‘11_rotate.jpg‘, [‘quality‘ => 50]); } //缩略图(压缩) public function actionThumb() { Image::thumbnail(‘11.jpg‘, 100, 50,ManipulatorInterface::THUMBNAIL_OUTBOUND) ->save(‘11_thumb.jpg‘); } //图片水印 public function actionWatermark() { Image::watermark(‘11.jpg‘, ‘11_thumb.jpg‘, [10,10]) ->save(‘11_water.jpg‘); } //文字水印 //字体参数 the file path or path alias (string) public function actionText() { Image::text(‘11.jpg‘, ‘hello world‘, ‘glyphicons-halflings-regular.ttf‘,[10,10],[]) ->save(‘11_text.jpg‘); } }
原文地址:https://www.cnblogs.com/l-zl/p/6422819.html