PHP code example of prowebber / pure_image

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

    

prowebber / pure_image example snippets




$pimage = new pure_image\PureImage();

$pimage->add->image('/abs_path/image.jpg');

$pimage->out->compress([
	'save_path'   => '/output_dir/file_name.jpg',
]);

$pimage->save->image();

$pimage = new pure_image\PureImage();
$pimage->add->image('/home/user/original.jpg');
$pimage->out->compress([
	'quality'   => 3,
	'save_path' => '/home/user/resized.jpg,
]);
$pimage->save->image();

$pimage = new pure_image\PureImage();
$pimage->add->image('/home/user/original.jpg');
$pimage->out->cover([
	'width'     => 250,
	'height'    => 250,
	'quality'   => 3,
	'save_path' => '/home/user/resized.jpg,
]);
$pimage->save->image();

$pimage = new pure_image\PureImage();
$pimage->add->image('/home/user/original.jpg');
$pimage->out->fit([
	'width'     => 250,
	'height'    => 250,
	'quality'   => 3,
	'save_path' => '/home/user/resized.jpg,
]);
$pimage->save->image();

$pimage = new pure_image\PureImage();
$pimage->add->image('/home/user/original.jpg');
$pimage->out->scale([
	'width'     => 250,
	'height'    => 250,
	'quality'   => 3,
	'save_path' => '/home/user/resized.jpg,
]);
$pimage->save->image();

$pimage->add->image('/home/user/original.jpg');

// Compress the image 
$pimage->out->compress([
	'quality'   => 3,
	'save_path' => '/home/user/compressed.jpg,
]);

// Create an image to fit the specified params
$pimage->out->fit([
	'width'     => 300,
	'height'    => 200,
	'quality'   => 3,
	'save_path' => '/home/user/resized.jpg,
]);

// Create another image to fit the specified params
$pimage->out->fit([
	'width'     => 600,
	'height'    => 400,
	'quality'   => 3,
	'save_path' => '/home/user/resized.jpg,
]);

// Create all images
$pimage->save->image();

$pimage->setMaxImageSize(10000000);

$result = $pimage->getResult();

$pimage->isErrorFree();

$pimage->showErrors();

$pimage->getErrors();

$pimage->getDetailedErrors();

$pimage->showDebug();

# Init pImage
$pImage = new PureImage();

# Add the image
$pImage->add->image('path/to/image.jpg');

# Check for errors triggered when the image was added
if(!$pImage->isErrorFree()){            # If there are errors
	
}

array[$image_id][$err_id] = Error message;