ImageEditor is a php library for easily creating / editing images. It uses the GD library for file generation.
- PHP 5.3 +
- GD lib
Using the library is very simple. Just include the autoload and you're done!
require "ImageEditor/autoload.php";
use ImageEditor\EditImage as EditImage;
To edit and create images you need to use the ImageEditor
class starting with the static method from
and passing the image that will be used as a model.
EditImage::from('images/zacarias.jpg')
then use the functions that will be applied to the image and save it
EditImage::from('images/zacarias.jpg')
->negate() // function
->save(); // save
See the wiki for more informations
Imagine you have a picture like this:
So you need to edit it and create 2 more photos following the rules:
- There will be 3 images in total (big, mid, small)
- All of them need to be clipped.
- Big will have a width of 300px
- Mid needs to be clearer and width of 200px
- The small will be in grayscale and width of 100px
How will I do this using this library?
EditImage::
from('images/zacarias.jpg', 'big') // create first image with alias 'big' using image in 'images' folder
->copy(['mid', 'small']) // and more 2 images with alias is 'mid' and 'small'
->crop('center center 300x*') // crop the image in the center using 300px width
->use('resize',[ // use function resize in ...
'mid' => '200x*', // mid => 200px in width
'small' => '100x*' // small => 100px in width
])
->brightness(100, 'mid') // increase brightness to 100 in mid
->grayscale('small') // tranform small in grayscale
->save(); // save imagess
The result is this ...