PHP code example of ride / lib-image

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

    

ride / lib-image example snippets




use ride\library\image\exception\ImageException;
use ride\library\image\GenericImageFactory;
use ride\library\image\Image;
use ride\library\system\file\File;

function foo(File $file) {
    // create an image factory, this one uses GD
    $imageFactory = new GenericImageFactory('gd');
    
    // use the image factory to create an image
    $image = $imageFactory->createImage();
    
    try {
        // read an image file
        $image->read($file);
    } catch (ImageException $exception) {
        // file could not be read or invalid image
        return false;
    }
    
    // get some properties of the image
    $hasTransparancy = $image->hasAlphaTransparancy();
    $transparentColor = $image->getTransparentColor();
    $dimension = $image->getDimension();
    
    $dimension->getWidth();
    $dimension->getHeight();
    
    // do some manipulations
    $dimension = $dimension->setWidth($dimension->getWidth() / 2);
    $image = $image->resize($dimension);
    
    $dimension = $dimension->setHeight($dimension->getHeight() / 2);
    $image = $image->crop($dimension);
    
    $image = $image->flip(Image::MODE_HORIZONTAL);
    $image = $image->rotate(90);
    $image = $image->blur();
    $image = $image->convertToGrayscale();
    
    // write the result back to the file
    $image->write($file);
}