PHP code example of mistralys / application-utils-image

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

    

mistralys / application-utils-image example snippets


use AppUtils\ImageHelper\ImageFiles\FileTypes\JPGFile;

JPGFile::factory('image.jpg')
    ->resampleByWidth('resized.jpg', 200);

use AppUtils\ImageHelper\ImageFiles\FileTypes\JPGFile;

JPGFile::factory('image.jpg')
    ->resampleByHeight('resized.jpg', 200);

use AppUtils\ImageHelper\ImageFiles\FileTypes\JPGFile;

JPGFile::factory('image.jpg')
    ->resample('resized.jpg', 200, 400);

use AppUtils\ImageHelper\ImageFiles\FileTypes\JPGFile;

JPGFile::factory('image.jpg')
    ->send('optional-name.jpg');

// You must manually exit the script after sending the image.
exit;

use AppUtils\ImageHelper\ImageFiles\FileTypes\JPGFile;

JPGFile::factory('image.jpg')
    // Set the second parameter to true to force the download.
    ->send('optional-name.jpg', true);

// You must manually exit the script after sending the image.
exit;

use AppUtils\ImageHelper;
use AppUtils\ImageHelper\ImageFiles\FileTypes\JPGFile;

// From a file path
$helper = ImageHelper::createFromFile('image.jpg');

// From an image class
$helper = JPGFile::factory('image.jpg')->createImageHelper();

// From a GD resource    
$resource = imagecreatefromjpeg('image.jpg');
$helper = ImageHelper::createFromResource($resource);

// New blank image
$helper = ImageHelper::createNew(200, 100);

use AppUtils\ImageHelper;

ImageHelper::createFromFile('image.jpg')
    ->resampleByWidth(200)
    ->save('resized.jpg');

use AppUtils\ImageHelper;

ImageHelper::createFromFile('image.jpg')
    ->resampleByWidth(200)
    ->sharpen(50)
    ->setQuality(80)
    ->save('sharpened.jpg');

use AppUtils\ImageHelper;

$size = ImageHelper::getImageSize('image.jpg');

echo $size->toReadableString();

use AppUtils\ImageHelper;

$average = ImageHelper::createFromFile('image.jpg')
    ->calcAverageColorRGB();

// Not needed anymore? Free up resources.    
$helper->dispose();