1. Go to this page and download the library: Download coercive/imgprocess 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/ */
coercive / imgprocess example snippets
use Coercive\Utility\ImgProcess\ImgProcess;
# INIT
$img = new ImgProcess;
# QUALITY (optional : default jpg 60 / png 0)
$img
->setJpgQuality(50)
->setPngCompression(5);
# EXAMPLE SET
$img
->setOverwriting(true)
->setInputPath('source/path/image_name.jpg')
->setOutputPath('output/path/new_image.jpg')
->setSourceCoordinate('RIGHT', 'BOTTOM')
->setOutputSize(1000, 1000);
# PROCESS
$bVerif = $img->sameSize();
// or
$bVerif = $img->myOwnSize(500);
// or
$bVerif = $img->crop();
// or
$bVerif = $img->cover();
// ...
# HANDLE ERRORS
if( !$bVerif ) {
if( $aError = $img->getError() ) {
foreach ($aError as $sMessage) { echo "<p>$sMessage</p>"; }
die('Shutdow After Process');
}
else {
die('Shutdow After Process : Unknow Error.');
}
}
# DETECT IMAGE QUALITY (base on linux 'identify')
$iQuality = ImgProcess::getImageQuality('/path/image_name.jpg');
use Coercive\Utility\ImgProcess\ImgResponsive;
$rii = (new ImgResponsive)
->overwrite(true)
->data($data)
->path('/rootpath/server/img', '/realpath/img')