Skip to content

Image cropping helper aimed to simplify GD functionality and more!

License

Notifications You must be signed in to change notification settings

wiejakp/ImageCrop

Repository files navigation

wiejakp/ImageCrop

Source Code Latest Version Software License PHP Version Build Status Coverage Status Total Downloads

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

Installation

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

Basic Usage

$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());
   ...
}

Reader And Writers

You can mix nad match what image resource is being loaded and what image resource is being generated out.

BMP Reader And Writer
$imageCrop = (new ImageCrop())
   ->setReader(BMPReader::class)
   ->setWriter(BMPWriter::class);
GIF Reader And Writer
$imageCrop = (new ImageCrop())
   ->setReader(GIFReader::class)
   ->setWriter(GIFWriter::class);
JPEG Reader And Writer
$imageCrop = (new ImageCrop())
   ->setReader(JPEGReader::class)
   ->setWriter(JPEGWriter::class);
PNG Reader And Writer
$imageCrop = (new ImageCrop())
   ->setReader(PNGReader::class)
   ->setWriter(PNGWriter::class);

Documentation

Check out the documentation website for detailed information and code examples.

Contributing

Contributions are welcome! Please read CONTRIBUTING for details.

Copyright and License

The wiejakp/ImageCrop library is copyright © Przemek Wiejak and licensed for use under the MIT License (MIT). Please see LICENSE for more information.

About

Image cropping helper aimed to simplify GD functionality and more!

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages