PHP code example of msgframework / image

1. Go to this page and download the library: Download msgframework/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/ */

    

msgframework / image example snippets

 php
...
$factory = new ImageFactory();

// Create ImageAdapter from $path with auto selected Adapter
$image = $factory->getImage($path);

// Create ImagickAdapter from $path
$image = $factory->getImage($path, 'Imagick');

// Create GDAdapter from $path
$image = $factory->getImage($path, 'GD');
 php
...
// Create ImagickAdapter from $path
$image = new \Msgframework\Lib\Image\Adapter\ImagickAdapter($path);

// Create GDAdapter from $path
$image = new \Msgframework\Lib\Image\Adapter\GDAdapter($path);
 php
...
$image = $factory->getImage($path);

$image->getWidth(); // Return width in px
$image->getHeight(); // Return height in px
 php
...
$image = $factory->getImage($path);

$image->resize(300, ImageAdapter::SIDE_WIDTH); // Set image width 300px
...
$image->resize(500, ImageAdapter::SIDE_HEIGHT); // Set image width 500px
$image->resize(800, ImageAdapter::SIDE_AUTO); // Set image width/height 800px by longest side
 php
...
$image = $factory->getImage($path);

$image->scale(300, ImageAdapter::SIDE_WIDTH); // Set image width 300px and scaled height
 php
...
$image = $factory->getImage($path);

$image->opacity(.5);
// Accepts float values from 0 to 1
 php
...
$image = $factory->getImage($path);

$image->quality(80);
// Accepts int values from 0 to 100
 php
...
$image = $factory->getImage($path);
...
$image->save($image->getPathName()); // Owerwrite Image
$image->save($newpath); // Save new Image
 php
...
$image = $factory->getImage($path);
...
$image->resize(600, ImageAdapter::SIDE_WIDTH);
$image->show();
 php
...
$image = $factory->getImage($pathImage);
$watermark = $factory->getImage($pathWatermark);
...
$image->watermark($watermark, ImageAdapter::WATERMARK_CENTER_CENTER, 20, 70, 70);
$image->save();
 php
...
$image = $factory->getImage($path);
...
$image->save()->destroy();
...
$dirPath = $image->getPath(); // Get path to image directory