yii2圖片處理擴展yii2-imagine的使用

示例控制器:php

<?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 app\controllers;

use Imagine\Image\ManipulatorInterface;
use yii\imagine\Image;

class ImageController extends \yii\web\Controller
{

    //裁剪
    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');
    }

}
相關文章
相關標籤/搜索