This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.
The preferred method of installation is via Composer. Run the following
command to install the package and add it as a requirement to your project's
composer.json
:
composer require wiejakp/image-crop
$imagePath = 'image.jpeg';
$imageCrop = (new ImageCrop())
->setReader(JPEGReader::class)
->setWriter(JPEGWriter::class);
// load resource into a reader
$imageCrop->getReader()->loadFromPath($imagePath);
// perform cropping actions
$imageCrop->crop();
// skip images that appear to be empty
if (false === $imageCrop->isEmpty()) {
// save cropped image to the drive
$imageCrop->getWriter()->write();
// do stuff with $imageCrop->getData() or $imageCrop->getDataUri()
$anchor = \sprintf('<a href="%s">anchor</a>', $imageCrop->getDataUri());
...
}
You can mix nad match what image resource is being loaded and what image resource is being generated out.
$imageCrop = (new ImageCrop())
->setReader(BMPReader::class)
->setWriter(BMPWriter::class);
$imageCrop = (new ImageCrop())
->setReader(GIFReader::class)
->setWriter(GIFWriter::class);
$imageCrop = (new ImageCrop())
->setReader(JPEGReader::class)
->setWriter(JPEGWriter::class);
$imageCrop = (new ImageCrop())
->setReader(PNGReader::class)
->setWriter(PNGWriter::class);
Check out the documentation website for detailed information and code examples.
Contributions are welcome! Please read CONTRIBUTING for details.
The wiejakp/ImageCrop library is copyright © Przemek Wiejak and licensed for use under the MIT License (MIT). Please see LICENSE for more information.