zoukankan      html  css  js  c++  java
  • yii2图片处理扩展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');
        }
    
    }
  • 相关阅读:
    Redis数据结构之字典
    多路复用
    Redis数据结构之SDS
    记一个图片转换神器vectorizer
    Java基础之面向对象上
    科学
    Linux内核源码分析之setup_arch (二)
    Linux内核源码分析之setup_arch (一)
    printk 流程分析
    多个线程顺序打印问题,一网打尽
  • 原文地址:https://www.cnblogs.com/shaoyikai/p/5390312.html
Copyright © 2011-2022 走看看