You can install ImageResize by composer. Add this row to your composer.json.
{
"require": {
"Innobotics/ImageResize": "1.*"
}
}
But do you want to include this pack use this:
require_once '/path/to/Innobotics/ImageResize.php';
You should create an image object.
$image = new \Innobotics\ImageResize();
Add types. The type contains the key, and the image's size.
$image->setType('large', 640, 480);
$image->setType('medium', 320, 240);
$image->setType('thumbnail', 160, 120);
$image->setType('content', 500, null); // You can add 'null' as height. It won't be cropped.
Add the source file.
$image->setSource('/home/notesz/teszt/bianka_160117.jpg');
Add the target folder.
$image->setTarget('/home/notesz/teszt/resized');
If you don't like the original name, you can add a new filename. (It is optional)
$image->setFileName('bianka.jpg'); //optional
Would you like to set compression? Add this one: (It is optional, the default value is 75)
$image->setCompression(100); //optional
Would you like to set compression type? Add this one: (It is optional, the default value is 9) You can find types here: https://www.geeksforgeeks.org/php-imagick-setimagecompression-function/
$image->setCompressionType(8); //optional
Would you like to use a file prefix? Add this one: (It is optional)
$image->setPrefix('image'); //optional
Would you like to disable progressive (setInterlace)? Add this one: (It is optional)
$image->setProgressive(false); //optional
Would you like to use retina sizes? Add this one: (It is optional)
$image->setRetina(true); //optional
If you don't want to save the original image you can disable it. Add this one: (It is optional)
$image->setSaveOriginal(false); //optional
Resize your image.
if ($image->resize() === true) {
print 'It\s okay! :)';
} else {
print 'Something happened!';
}
Then you can reach the result.
print_r($image->getResult());
If the resize was success, the result is:
Array
(
[status] => success
[message] => Array
(
[files] => Array
(
[large] => image_bianka_large.jpg
[medium] => image_bianka_medium.jpg
[thumbnail] => image_bianka_thumbnail.jpg
[original] => image_bianka.jpg
)
)
)
But the resize was false, the result is:
Array
(
[status] => error
[message] => unable to open image `/home/notesz/teszt/IMG_790s7.jpg': No such file or directory @ error/blob.c/OpenBlob/2638
)