Top 6 PHP Libraries for Manipulating Images

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.

<?php
 
$imagine = new Imagine\Gd\Imagine();

$imagine = new Imagine\Imagick\Imagine();

$imagine = new Imagine\Gmagick\Imagine();
 
$size    = new Imagine\Image\Box(40, 40);
 
$mode    = Imagine\Image\ImageInterface::THUMBNAIL_INSET;

$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.


$img = Image::make('public/foo.jpg');
 

$img->resize(320, 240);
 

$img->insert('public/watermark.png');
 

$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)) { 
 
    $gfe = new GifFrameExtractor();
    $gfe->extract($gifFilePath);
 
    
}

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 !




$frames = array(
    imagecreatefrompng("/../images/pic1.png"), 
    "/../images/pic2.png", 
    file_get_contents("/../images/pic3.jpg"), 
    'http://thisisafakedomain.com/images/pic4.jpg', 
);
 

$durations = array(40, 80, 40, 20);
 

$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.

<?php
require '../vendor/autoload.php';
 

$image = new \NMC\ImageWithText\Image(dirname(__FILE__) . '/source.jpg');
 

$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);
 

$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);
 

$image->render(dirname(__FILE__) . '/destination.jpg');

6. ImageWorkshop

Really flexible and easy-to-use PHP class to work with images using the GD Library