How to install and use YII2 plug-in Imagine

Source: Internet
Author: User
Tags php class yii
Imagine is an object-oriented PHP class library for picture operations. This class library can handle some commonly used operations such as resizing, cropping, applying filters, and so on. Its color class library can be used to generate RGB values for any pairs of colors. It also provides some ways to draw graphs such as arcs, ellipses, lines, slices, etc. In addition, you can use a flexible font class to load any font file, and then insert the text into the picture. Imagine is a class library that will be updated frequently and will be implemented in the future: Chart generation, fillet filters and more. This article mainly and you introduce YII2 third party class library plug-in Imagine installation and use, with a certain reference value, interested in small partners can refer to, hope to help everyone.

YII2 installation Imagine

Imagine manual Download and installation here will not do the introduction, can self-Baidu. This article describes Yii2 's Composer way to install Imageine.

Method One


PHP Composer.phar require--prefer-dist yiisoft/yii2-imagine

Method Two

Add the following code in the Require field within the project Composer.json file:


"Yiisoft/yii2-imagine": "~2.1.0"

Then execute the command (CMD) in the project root directory:


Composer require Yiisoft/yii2-imagine

Yii2 using Imagine


Use yii\imagine\image; $srcImg = Yii::getalias (' @webroot/test.jpg '); $aimImg = Yii::getalias (' @webroot/testdeal.jpg ') ; $srcTTF = Yii::getalias (' @webroot/img/symbol.ttf ');//thumbnail//parameter inset = fixed frame thumbnail//Picture full thumbnail in 200x100 box// Note: The width or height of the frame must have a smaller than the actual size of the picture, otherwise directly return the source map size Image::thumbnail ($SRCIMG, Max, +, ' inset ')->save ($aimImg, [' Quality ' = 100])///////////////////////Outbound///Parameter = default value of single dimension and center intercept//This parameter is the function's defaults, it will capture as many pictures as you can, but will not exceed the image Range/Example: The source graph 500x200, then according to the height Then center intercept 200x100//Example: The source graph 400x350, then according to the width of 200 contraction rate (to 200x175), and then center intercept 200x100//Example: the source map 100x80, then the non-shrinking rate does not intercept, directly return to the source map 100x80image:: Thumbnail ($SRCIMG, Max, Max, ' outbound ')->save ($aimImg, [' Quality ' =>100]);//thumbnail//by width 200 thumbnail, highly adaptive Image:: Thumbnail ($srcImg, h, null)->save ($AIMIMG, [' Quality ' =>100]);//thumbnail//by height 100 abbreviation, Width adaptive image::thumbnail ($srcImg , NULL,->save ($AIMIMG, [' Quality ' =>100]);//Cut//Parameters: Source graph, width, height, starting point//Save the source file $srcImg to $aimImgImage:: Crop ($ Srcimg, [100,100])->save ($AIMIMG);//rotation//Not studied Image::frame (' @webroot/img/test-image. jpg ', 5, ' 666 ', 0)->rotate ( -8)->save (Yii::getalias (' @webroot/img/thumb-test-frame.jpg '), [' quality ' = 100 ])///watermark//Not studied Image::watermark (' @webroot/img/test-image.jpg ', ' @webroot/img/watermark.jpg ', [10,10])->save (Yii: : Getalias (' @webroot/img/thumb-test-watermark.jpg '), [' quality ' + 100]);//text watermark//Parameters: source, text, font, starting point, font configuration image:: Text ($srcImg, ' Hello World ', $srcTTF, [100,100], [' color ' = ' 000000 ', ' Size ' =>50])->save ($AIMIMG, [' Quality ' = >100]);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.