Here I am going to share Top 6 PHP Libraries for Manipulating Images. If you have bunch of images and you want to modify bulk images using php then these libraries for you. These all are Really flexible and easy-to-use PHP Libraries to work with images using the GD Library.
1. Imagine
Imagine is a OOP library for image manipulation built in PHP 5.3 using the latest best practices and thoughtful design that should allow for decoupled and unit-testable code.
$imagine = new Imagine\Gd\Imagine();
// or
$imagine = new Imagine\Imagick\Imagine();
// or
$imagine = new Imagine\Gmagick\Imagine();
$size = new Imagine\Image\Box(40, 40);
$mode = Imagine\Image\ImageInterface::THUMBNAIL_INSET;
// or
$mode = Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
$imagine->open('/path/to/large_image.jpg')
->thumbnail($size, $mode)
->save('/path/to/thumbnail.png')
;
|
2. Intervention Image
Intervention Image is a PHP image handling and manipulation library providing an easier and expressive way to create, edit, and compose images. The package includes ServiceProviders and Facades for easy Laravel integration.
// open an image file $img = Image::make('public/foo.jpg'); // resize image instance $img->resize(320, 240); // insert a watermark $img->insert('public/watermark.png'); // save image in desired format $img->save('public/bar.jpg'); |
3. GifFrameExtractor
GifFrameExtractor is a PHP class that separates all the frames (and their duration) of an animated GIF. The class helps you to separate all the frames of an animated GIF, for example to watermark them and then to generate a new watermarked and animated GIF.
$gifFilePath = 'path/images/picture.gif'; if (GifFrameExtractor::isAnimatedGif($gifFilePath)) { // check this is an animated GIF $gfe = new GifFrameExtractor(); $gfe->extract($gifFilePath); // Do something with extracted frames ... } |
4. GifCreator
GifCreator is a PHP class to create animated GIF from multiple images. This class helps you to create an animated GIF image: give multiple images and their duration and that’s it !
// Create an array containing file paths, resource var (initialized with imagecreatefromXXX), // image URLs or even binary code from image files. // All sorted in order to appear. $frames = array( imagecreatefrompng("/../images/pic1.png"), // Resource var "/../images/pic2.png", // Image file path file_get_contents("/../images/pic3.jpg"), // Binary source code 'http://thisisafakedomain.com/images/pic4.jpg', // URL ); // Create an array containing the duration (in millisecond) of each frames (in order too) $durations = array(40, 80, 40, 20); // Initialize and create the GIF ! $gc = new GifCreator(); $gc->create($frames, $durations, 5); |
5. Image with Text
This class makes it super easy to render images with multiple, independently styled text blocks. You can control each text block’s alignment, color, font, line height, and size. You may also position each text block with specific X and Y coordinates relative to the source image.
require '../vendor/autoload.php';
// Create image
$image = new \NMC\ImageWithText\Image(dirname(__FILE__) . '/source.jpg');
// Add styled text to image
$text1 = new \NMC\ImageWithText\Text('Thanks for using our image text PHP library!', 3, 25);
$text1->align = 'left';
$text1->color = 'FFFFFF';
$text1->font = dirname(__FILE__) . '/Ubuntu-Medium.ttf';
$text1->lineHeight = 36;
$text1->size = 24;
$text1->startX = 40;
$text1->startY = 40;
$image->addText($text1);
// Add another styled text to image
$text2 = new \NMC\ImageWithText\Text('No, really, thanks!', 1, 30);
$text2->align = 'left';
$text2->color = '000000';
$text2->font = dirname(__FILE__) . '/Ubuntu-Medium.ttf';
$text2->lineHeight = 20;
$text2->size = 14;
$text2->startX = 40;
$text2->startY = 140;
$image->addText($text2);
// Render image
$image->render(dirname(__FILE__) . '/destination.jpg');
|
6. ImageWorkshop
Really flexible and easy-to-use PHP class to work with images using the GD Library