PHP Library for Comparing Images & Advanced Filters
Open Source PHP API includes support for image comparison, smart cropping, image blending, GIF animation, 5 resize modes, and many more.
Grafika is very easy to use and powerful image processing PHP library that is blended with some unique features enabling software developers to create and manipulate their images and graphics inside their PHP applications. Grafika is based on Imagick and GD, so there is no need to worry about the differences between GD and Imagick API, Grafika normalizes these operations for you and makes your job easy.
The Grafika library has provided support for basic as well as several advance image creation and processing features. The library can be used to generate image thumbnails quickly and having very high quality. The library has also included support for intelligent tailoring as well as image attribute processing with just a couple of lines of code.
The Grafika library contains some advanced features that make it unique from other available PHP libraries, such as applying smart cropping, compare images, advance filters, image blending, animated GIF support, 5 resize modes and more. It has also included support for some common features like image cloning, create blank images, make a copy of the image, apply watermark on the image, and many more.
At A Glance
An overview of Grafika features.
- Create editors
- Creating images
- Resizing images
- Compare images
- Smart crop
- Animated GIF
- Copy image
- Edit images
- Image cloning
- Apply watermark
- Display images
- Image compression
- Draw text
- Image effect
- Image encoding
Grafika supports popular Image file formats listed below.
Grafika works with PHP >= 5.3 & above
Getting Started with Grafika
The recommended way to install Grafika is via Composer. Inside your project directory, open the command line and type the following command to install it.
Install Grafika via composer
$ composer require kosinix/grafika:dev-master --prefer-dist
Images Creation via PHP APIs
The open source Grafika library allows software developers to generate different kinds of images inside their own PHP application with a couple of lines of code. The most common way of making an image is by using the editor's open method. You easily create a blank image as well as create a copy of an image using the clone keyword inside your code. Moreover, you can also blend, fill, flip, set opacity as well as resize and crop images with ease.
Create Image via PHP API
// Create a Blank Image use Grafika\Grafika; $image = Grafika::createBlankImage(100,100); // Another way is to use editor open method use Grafika\Grafika; $editor = Grafika::createEditor(); $editor->open( $image, 'path/to/image.jpg'); //Adjust size of the image $editor->resizeExact( $image, 200, 100 );
Compare Images inside PHP Apps
The Grafika library gives software programmers the power to programmatically compare their images inside their own apps. It can compare the similarity between two images as well as gives you the ability to determine if the two images are equal or not. The great thing is that it can do a pixel-by-pixel comparison to determine if two images are exactly the same. It will compare if the two images are of the same width and height. If the dimensions differ, it will return false. If the dimensions are equal, it will loop through each pixel. If one of the pixels doesn't match, it will return false. The pixels are compared using their RGB (Red, Green, Blue) values.
Compare Images for Similarity via PHP
require_once 'path/to/grafika/src/autoloader.php'; // Automatically load our needed classes use Grafika\Grafika; // Import package $editor = Grafika::createEditor(); // Create editor $hammingDistance = $editor->compare( "image1.jpg", "image-2.jpg" );
Smart Image Cropping
Image cropping is the removal of undesirable areas from a photographic or image. Cropping can be used to make the image size reduced or change the aspect ratio of an available image. The Grafika library has included features for basic as well as smart cropping via PHP. The smart cropping feature is very useful and where the library decides the crop position with the important regions of the images preserved.
Smart Image Cropping inside PHP Apps
$editor->open( $image, $input ); $editor->crop( $image, 200, 200, 'smart' ); $editor->save( $image, 'output.jpg' );
Animated GIF Support
Image cropping is the removal of undesirable areas from a photograph or image. Cropping can be used to make the image size reduced or change the aspect ratio of an available image. The Grafika library has included features for basic as well as smart cropping via PHP. The smart cropping feature is very useful and where the library decides the crop position with the important regions of the images preserved.
Flattening Animated GIF via PHP API
use Grafika\Grafika; $editor = Grafika::createEditor(); $editor->open( $image, 'animated.gif' ); $editor->flatten( $image ); $editor->save( $image, 'output.gif' );