PHP code example of msztorc / image-processor

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

    

msztorc / image-processor example snippets



$obj = new ImageProcessor('imagick', 'file.jpg'); // or 'gd' (default)
$obj->resize(100, 50, true, false); //width, height, aspect_ratio, enlarge
$obj->clear(); //free memory


ImageProcessor::imagick_resize('input-file.jpg', 'output-file.jpg', 800, 800); //infile, outfile, width, height, quality = 100, aspect_ratio = true, filter = imagick::FILTER_LANCZOS


ImageProcessor::epeg_resize('input-file.jpg', 'output-file.jpg', 800, 800); //infile, outfile, width, height, quality = 100, aspect_ratio = true



$obj = new ImageProcessor('imagick', 'infile.jpg');
// or
$obj2 = new ImageProcessor('gd', 'infile.jpg');

// clean constructor
$obj3 = new ImageProcessor(); //gd is default argument in constructor
$obj3->open('infile.jpg'); //open image


$obj->grayscale();

$obj->negative();

$obj->brightness($threshold); // +/- 100

$obj->colorize(80,90,60); //rgb

$obj->sepia();

$obj->grayscale();
$obj->colorize(90,60,40);

$obj->display();

$obj->save('outfile.jpg', 99); //filename, JPEG quality

$obj->image()->resizeImage(1200,1200, imagick::FILTER_LANCZOS, 1, true); //resize using Imagick object; object must be init with second argument 'imagick'

$obj = new ImageProcessor();
$obj->open_image('imagick', $file);
//$obj->image()->setOption('jpeg:size', '300x300'); //uncomment this if you want increase speed of resize
$obj->image()->resizeImage(300,300, imagick::FILTER_LANCZOS, 1, true);

$obj->save($outfile, 75);
$obj->display();

$image = new Imagick();
$image->setOption('jpeg:size', '500x500');
$image->readImage('file.jpg');

//$time_start = microtime(true);

$obj = new ImageProcessor('imagick');
$obj->image()->setOption('jpeg:size', '300x300');
$obj->open($file);

$obj->image()->resizeImage(300,300, imagick::FILTER_LANCZOS, 1, true);

$obj->save($outfile, 99);

//$time_end = microtime(true);
//$time = $time_end - $time_start;
//echo $time ."\n\n";