当前位置: 首页 > 工具软件 > Imagine-PHP > 使用案例 >

yii2图片处理扩展yii2-imagine的使用

强安和
2023-12-01

示例控制器:

<?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');
    }

}

 

转载于:https://www.cnblogs.com/shaoyikai/p/5390312.html

 类似资料: