Image Merge
A simple PHP libraty to manipulate images, it support GIF, PNG and JPG, (*1)
, (*2)
Requirement
PHP >= 5.6 with GD support
*For some additional features (for example image distortion) ImageMagick binaries are required., (*3)
Getting Started
Install library with composer, (*4)
composer require jackal/image-merge
Usage
Minimal example
$imageMerge = new ImageMerge();
$imageBuilder = $imageMerge->getBuilder('/path/to/my/file.png'); #or URL, or resource, or binary content
$imageBuilder->resize(620,350)
$imageBuilder->rotate(90);
Get the image content directly to the output, (*5)
[...]
echo $imageBuilder->getImage()->toPNG()->getContent();
Save image to path, (*6)
[...]
$builder->getImage()->toPNG('/path/to/the/image.png');
Get image Response object (Compatible with Symgony projects), (*7)
[...]
return $imageBuilder->getImage()->toPNG()
resize
At least one parameter is required
In case just one parameter is passed, it will resize maintaining the aspect ratio of the image, (*8)
$imageBuilder->resize(620,null);
#or
$imageBuilder->resize(null,200);
If both parameters are passed, it could stretch the image, (*9)
$imageBuilder->resize(400,200);
thumbnail
Similar to Resize but in case the aspect ratio is not respected, it will crop the image (using cropCenter), (*10)
$imageBuilder->thumbnail(400,400);
rotate
Rotate the image (counterclockwise), (*11)
$imageBuilder->rotate(180);
*In case of particular angle (30, 45, etc..) it will create blank area to fill the empty spaces, (*12)
grayscale
Add a graysclae filter to the image, (*13)
$imageBuilder->grayScale();
brightness
Adjusts the brightness of the image, (*14)
$imageBuilder->brightness(10);
blur
Adds blur effect on the image, (*15)
$imageBuilder->blur(20);
pixelate
Adds "Pixel" effect on the image, (*16)
$imageBuilder->pixelate(20);
crop and cropCenter
Crop
Crop the image according to the x and y coords and the output dimention passed, (*17)
$point_x = 10,
$point_y = 15;
$width = 50,
$height = 50;
$imageBuilder->crop($point_x,$point_y,$width,$height);
Crop at the center of the image according to the width and height of the output image, (*18)
$width = 50,
$height = 50;
$imageBuilder->cropCenter($point_x,$point_y,$width,$height);
border
It adds border to the image (fill inside the rect), (*19)
$stroke = 20;
$colorHex = '3399ff';
$builder->border($stroke,$colorHex);
Experimental features that will likely change in the future
addText
It adds text inside the image, (*20)
$text = new Jackal\ImageMerge\Model\Text\Text('this is the text', Font::arial(), 12, new Color('ABCDEF'));
$builder->addText($text, 10, 20);
addSquare
It adds a square (color-filled) on the image, (*21)
$builder->addSquare(10, 10, 20, 20, 'ABCDEF');
===========================================================================, (*22)
Author
-
Luca Giacalone (AKA JackalOne)
License
This project is licensed under the MIT License, (*23)