Imagine is an OOP library for image manipulation. It allows you to crop, resize, and perform other manipulations with different images with the help of GD, Imagic, and Gmagic PHP extensions. Yii2-Imagine is a lightweight static wrapper for the library.
composer require yiisoft/yii2-imagine
In your projects, you can use the extension in two ways:
You can use an instance of the original Imagine
library class:
$imagine = new ImagineGdImagine(); // or $imagine = new ImagineImagickImagine(); // or $imagine = new ImagineGmagickImagine();
However, this depends on the existing corresponding PHP extensions in your system. You can use the getImagine()
method:
$imagine = yiiimagineImage::getImagine();
You can use the crop()
, thumbnail()
, watermark()
, text()
, and frame()
methods for common high-level manipulations like this:
<?php use yiiimagineImage; Image::crop('path/to/image.jpg', 100, 100, ManipulatorInterface::THUMBNAIL_OUTBOUND) ->save('path/to/destination/image.jpg', ['quality' => 90]);
See the signatures of all supported methods in the source code of the yiiimagineBaseIm
age
class for more details.
The extension prepares user data, creates an original Imagine object, and calls the corresponding method on it. All methods return this original image object. You can continue to manipulate the image or save the result to your disk.
18.224.246.203