2017 © Pedro Peláez
 

library image

Webiny Image Component

image

webiny/image

Webiny Image Component

  • Friday, September 29, 2017
  • by SvenAlHamad
  • Repository
  • 2 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 23 Versions
  • 0 % Grown

The README.md

Image Component

The Image component provides basic functions for manipulating images. Component also fixes the incorrect rotation on pictures taken by a smartphone like iPhone or Android., (*1)

Install the component

The best way to install the component is using Composer., (*2)

composer require webiny/image

For additional versions of the package, visit the Packagist page., (*3)

Usage

This component is deeply coupled with the Storage component, so it's advised that you get yourself familiar with that component first, if you already haven't., (*4)

Under basic functions it's meant that you can do these manipulations on any image: - resize - crop - rotate, (*5)

But before you can do any of the manipulations, you must first load an image. You can load an image from several different sources by calling appropriate methods on ImageLoader class: - create - creates a blank image - open - create an image from the given File storage instance - load - create an image from the given binary string - resource - create an image from the given (stream) resource, (*6)

Each of these methods returns an instance of ImageInterface. Using ImageInterface you can perform the defined manipulations on the loaded image., (*7)

Once you are done manipulating the image you can either save it by calling the save method, or you can output the image by calling the show method., (*8)

Here is a usage example:, (*9)

// storage
$imageStorage = \Webiny\Component\ServiceManager\ServiceManager::getInstance()->getService('storage.local');
$image = new \Webiny\Component\Storage\File\File('embed.jpg', $imageStorage);

// load the image using the `open` method
$imgInstance = \Webiny\Component\Image\ImageLoader::open($image);

// perform manipulations
$imgInstance->resize(800, 800)
            ->crop(200, 200, 50, 40);
            ->rotate(30, 'bfbfbf');

// save the new image
$destination = new \Webiny\Component\Storage\File\File('embed-rotated.jpg', $imageStorage);
$result = $imgInstance->save($destination); // if you don't set the destination, the original image will be overwritten

Using ImageTrait

An easier way of loading the image and creating instances of ImageInterface is using the ImageTrait. Here is an example of loading the image from the \Webiny\Component\Storage\File\File object:, (*10)

class MyClass{
    use \Webiny\Component\Image\ImageTrait;

    function __construct(){
        $imageStorage = \Webiny\Component\ServiceManager\ServiceManager::getInstance()->getService('Storage.Local');
        $image = new \Webiny\Component\Storage\File\File('embed.jpg', $imageStorage);

        $imgInstance = $this->image($image);

        $imgInstance->resize(800, 800);
        $imgInstance->crop(200, 200, 50, 40);
        $imgInstance->rotate(30, 'bfbfbf');

        $imgInstance->show();
    }
}

Here is another example where we load the image by file storage key and storage driver:, (*11)

``` php class MyClass{ use \Webiny\Component\Image\ImageTrait;, (*12)

function __construct(){
    $imgInstance = $this->image('embed.jpg', 'Local');

    $imgInstance->resize(800, 800);
    $imgInstance->crop(200, 200, 50, 40);
    $imgInstance->rotate(30, 'bfbfbf');

    $imgInstance->show();
}

}, (*13)


So as you can see, you can load and create ImageInterface instances either by passing directly the File object, or by passing the file key together with the name of the storage service. ## Bridge The default bridge for image library uses `Imagine` library (https://github.com/avalanche123/Imagine) by Bulat Shakirzyanov which perform all the image manipulations. If you wish to expand or change the current bridged library you need to create two classes: - a loader class that implements `Webiny\Component\Image\Bridge\ImageLoaderInterface` - an image manipulation class that extends `Webiny\Component\Image\Bridge\AbstractImage` After that just change the `Bridge` in the configuration and the framework will use your bridge instead the default one. ## Configuration The `Image` component requires very little configuration. Here is an example: ```yaml Image: Library: gd Quality: 90

The Library parameter defines which image library will be used. Supported libraries by Imagine library are: - gd - uses native PHPs GD library - imagick - uses ImageMagick library which requires php-imagick extension - gmagick - uses GraphicsMagick API which also requires php-gmagick extension, (*14)

The Quality parameter defines at which quality to save the image. The default quality is 90 (max is 100)., (*15)

To register the config with the component, just call Image::setConfig($pathToYamlConfig)., (*16)

Resources

To run unit tests, you need to use the following command:, (*17)

$ cd path/to/Webiny/Component/Image/
$ composer.phar install
$ phpunit

The Versions

29/09 2017

dev-master

9999999-dev http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

29/09 2017

1.6.x-dev

1.6.9999999.9999999-dev http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

29/09 2017

v1.6.0

1.6.0.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

29/09 2017

v1.6.1

1.6.1.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

08/09 2017

1.5.x-dev

1.5.9999999.9999999-dev http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

08/09 2017

v1.5.0

1.5.0.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

21/08 2016

1.4.x-dev

1.4.9999999.9999999-dev http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

21/08 2016

v1.4.3

1.4.3.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

04/02 2016

v1.4.0

1.4.0.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

04/02 2016

v1.4.1

1.4.1.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

04/02 2016

v1.4.2

1.4.2.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

16/03 2015

1.3.x-dev

1.3.9999999.9999999-dev http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

16/03 2015

v1.3.0

1.3.0.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

04/02 2015

1.2.x-dev

1.2.9999999.9999999-dev http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

04/02 2015

v1.2.0

1.2.0.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

04/02 2015

v1.2.1

1.2.1.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

04/02 2015

v1.2.2

1.2.2.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

04/02 2015

v1.2.3

1.2.3.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

28/11 2014

v1.1.1

1.1.1.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

23/11 2014

1.1.x-dev

1.1.9999999.9999999-dev http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

23/11 2014

v1.1.0

1.1.0.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

20/09 2014

1.0.x-dev

1.0.9999999.9999999-dev http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick

20/09 2014

v1.0.0

1.0.0.0 http://www.webiny.com/

Webiny Image Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

image resize crop gd imagick gmagick