What is Grafika?
Grafika is an advance image processing and graphics library for PHP.
Download .zip GithubWhy Grafika?
Why another image manipulation lib? There are a bazillion other libs for PHP already, why reinvent the wheel? Well...
Unique Features
These are the features that makes Grafika unique from other libs:
- Smart Crop - Grafika can guess the crop position based on the image content where the most important regions are preserved.
- Animated GIF Support - It can resize animated GIFs on both GD and Imagick. On GD, Grafika uses its own GIF parser to do this.
- 5 Resize Modes - Resize is a first class citizen in Grafika. Call them directly using resizeFit, resizeFill, resizeExact, resizeExactWidth, and resizeExactHeight or use the generic resize api.
- Image Compare - Find how similar two images are or check if they are exactly equal.
- Advance Filters - Sobel edge-detection, diffusion and ordered dithering. More will be added in future releases.
- Image Blending - Blend 2 images using the following modes: normal, multiply, overlay and screen.
- Normalized API - No need to worry about the differences between GD and Imagick API, Grafika normalizes these operations for you.
Basic Filters
Grafika also support the basic filters commonly found in other libs:
- Blur
- Brightness
- Colorize
- Contrast
- Gamma
- Invert
- Pixelate
- Sharpen
See Filters section for more info.
Drawing Objects
- CubicBezier
- Ellipse
- Line
- Polygon
- QuadraticBezier
- Rectangle
See Drawing Objects section for more info.
Easy Image Manipulation
Grafika makes it easier to do image manipulation in PHP.
Consider the following code using PHP's default built-in image lib, GD.
It will resize a jpeg image to exactly 200x200 pixels:
$gd = imagecreatefromjpeg( 'path/to/jpeg/image.jpg' ); // Open jpeg file
$newImage = imagecreatetruecolor(200, 200); // Create a blank image
// Resize image to 200x200
imagecopyresampled(
$newImage,
$gd,
0,
0,
0,
0,
200,
200,
imagesx($gd),
imagesy($gd)
);
imagedestroy($gd); // Free up memory
imagejpeg( $newImage, 'path/to/edited.jpg', 90 ); // Save resized image with 90% quality
imagedestroy($newImage); // Free up memory
Now consider doing the same using grafika:
use Grafika\Grafika;
$editor = Grafika::createEditor();
$editor->open( $image, "path/to/jpeg/image.jpg" );
$editor->resizeExact( $image, 200, 200 );
$editor->save( $image, "path/to/edited.jpg", null, 90 );
You can even chain the api calls (think jQuery):
use Grafika\Grafika;
Grafika::createEditor()
->open( $image, "path/to/jpeg/image.jpg" )
->resizeExact( $image, 200, 200 )
->save( $image, "path/to/edited.jpg", null, 90 );
See docs for more info.