Imagine library

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.

Getting ready

  1. Create a new application by using composer, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
  2. Install the extension with the following command:
    composer require yiisoft/yii2-imagine
    

How to do it…

In your projects, you can use the extension in two ways:

  • Using it as a factory
  • Using inner methods

Using it as a factory

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();

Using inner methods

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.

How it works…

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.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.246.203