PHP code example of lireincore / image

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

    

lireincore / image example snippets


//Use basic effects
use LireinCore\Image\Manipulators\Imagine;
use LireinCore\Image\PostProcessors\OptiPng;

$image = (new Imagine())
    ->open('/path/to/image.jpg')
    ->resize(1000, 500)
    ->grayscale()
    ->blur(2)
    ->text('Hello word', 'Verdana');
    ->save('/path/to/new_image.png', ['format' => 'png', 'png_compression_level' => 7]);

$postProcessor = new OptiPng();
$postProcessor->process('/path/to/new_image.png'); //optimize image

//Also you can add extended effects
use LireinCore\Image\Manipulator;
use LireinCore\Image\Manipulators\Imagine;
use LireinCore\Image\Effects\Overlay;
use LireinCore\Image\Effects\ScaleDown;
use LireinCore\Image\Effects\Fit;
use LireinCore\Image\PostProcessors\JpegOptim;

$image = (new Imagine(Manipulator::DRIVER_GD))
    ->open('/path/to/image.jpg')
    ->apply(new Overlay('/path/to/watermark.png', 70, 'right', 'bottom', '50%', '50%'))
    ->grayscale()
    ->apply(new ScaleDown('50%', '50%', true))
    ->apply(new Fit('center', 'center', '200', '90', '#f00', 20, true))
    ->negative()
    ->save('/path/to/new_image.jpg');

$postProcessor = new JpegOptim();
$postProcessor->process('/path/to/new_image.jpg'); //optimize image
 bash
$ php composer.phar