PHP code example of webiny / image

1. Go to this page and download the library: Download webiny/image library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webiny / image example snippets


// 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

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();
	}
}
 php
class MyClass{
	use \Webiny\Component\Image\ImageTrait;

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

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

		$imgInstance->show();
	}
}