Download from GitHub.
Easy image is an easy to use image manipulation library written entirely in PHP and implemented in a single PHP class. It's intended to be used where ImageMagick is not available, and works on PHP 5.3 and up. It can be used to edit, apply filters, resize, animate, convert and get information about images in several formats.
Input types:
|
as
|
Output types:
|
as |
Get Image Info: |
|
|
|
Utilities & Helpers: |
|
|
|
EasyImage was meant to be easy to use. To that end, most of it's methods are chainable, and the image can be sent to the browser by simply echoing the class. This allows you to generate and alter images in a single statement.
EasyImage has a universal constructor: EasyImage::Create(). This method is used to create your EasyImage object no matter what the input type.
$path = realpath(dirname(__FILE__));
echo EasyImage::Create("$path/image.png");
echo EasyImage::Create("www.example.com/images/logo.jpg");
echo EasyImage::Create(50, 50);
echo EasyImage::Create("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACg0lEQVR4nO3XTWhUVxQH8F+ipopgCVqTuFFLtQstwS+IChpXrbrr2iJ+rQviwi666aIFQRAFN7pzIyIBUXChKFW0UMGFdqWgLTRG0eBHaltjYro49zmTl3mZNxOhC/3DcGfOvef7vf+5wwe872hpUm8eVqITH+MJBnADL99NaBMxDTtwDaMYq/H5F+fxVVmjZSvQg+NYhmFcwSX045moyCJ8iTXJ7iXsxB9lgynCNyKzYRzBJ3XOL8VpUZFHWDcV59uSoYdNGNqGf/A3VjfjvEdk/hCLmzGAXlG5fnQ1otiKW0l5bZPOM+wRVTzRiNL2pHR4is4zXMUbdJdV+FlkP79KNhv7RW+L0Ia9IuvqN2yTSOhQGefteI2LOfmPKu/7hgLdvVVnvq6St+Ix7uYVWmsY6cZ0XM7Jh9I6hr8KAhgq+P5GVPUzwZxvMb2GkY609ufkB3AfD3CzIIDjGEwBXsjtZfY68HyyAOak9UVOPoqTBY4zjKGvYC9zOq4CtVowmNa5dZw1ioxBn9QLYCCtzZJPERapsOqk+Ej0sFafl2BhHf0VJlZvlqDkX+s5z9Anol2ek98Q43hmgV6XqOCxnDybKd+XDWBjUjibk68U8+EX4wdMC7aK0dtvfAXacE9UtbNsAHAuBbE7J+/FU5V+3q76fQef5s4fTXs/NOIcFohshrE5t9cuaPmMqMYp7BLZVmNfcn5dPFsNY5VgtBF8q/wNqk0l83sq5NYUvhAMOCYewi2YUXB2tpikv6fz14wfaBNQNqN5+ElcSqcJlryKPwXDZXfC9Sqv8cGk86qkj1L4PBn9zcQb8ajo9XcaKHmz/wsILugQ3D4oLqAjU7D3Af8P/gN1UJotAMKqGQAAAABJRU5ErkJggg==");
echo EasyImage::Create(
"Hello, World",
13,
"#FF0000",
"fancyFont.ttf"
);
Note: EasyImage only supports very basic html, along with sudo CSS style. Here are the allowed tags and styles.
$fonts = array("courier"=>"courier.ttf", "impact"=>"impact.ttf");
$HTML = "<span style='font-size:15;'>Hello, </span><span style='font-face:impact'>world</span>";
echo EasyImage::Create($HTLM, fonts);
$sources = array("frame1.gif", "frame2.gif", "frame3.gif");
echo EasyImage::Create($sources);
All the editing methods are chainable for convenience.
echo EasyImage::Create($file)->borderRadius();
echo EasyImage::Create($file)->
addWatermark(
"uploaded to mysite.com",
18,
"#000",
"courier.ttf"
);
echo EasyImage::Create($file)->makeOpaque(56);
echo EasyImage::Create($file)->addOverlay($overlay, 0, 0);
echo EasyImage::Create($file)->blackAndWhite();
echo EasyImage::Create($file)->crop(32, 32);
echo EasyImage::Create($file)->autoCrop();
echo EasyImage::Create($file)->transparentToColor($hexColor);
echo EasyImage::Create($file)->removeColor($hexColor);
echo EasyImage::Create($file)->replaceColor("#ff0000", "#00ffff");
echo EasyImage::Create($file)->scale(150);
echo EasyImage::Create($file)->resize(150, 200);
echo EasyImage::Create($file)->rotate(180);
echo EasyImage::Create($file)->rotate(500, 300);
echo EasyImage::Create($file)->reverseColors();
echo EasyImage::Create($file)->greyScale();
echo EasyImage::Create($file)->adjustBrightness(150);
echo EasyImage::Create($file)->adjustContrast(150);
echo EasyImage::Create($file)->edgeDetect();
echo EasyImage::Create($file)->emboss();
echo EasyImage::Create($file)->gaussianBlur();
echo EasyImage::Create($file)->selectiveBlur();
echo EasyImage::Create($file)->sketch();
echo EasyImage::Create($file)->vignette();
echo EasyImage::Create($file)->alphaMap();
echo EasyImage::Create($file)->removeTransparency();
echo EasyImage::Create($file)->perspective();
echo EasyImage::Create($file)->pixelate(10);
echo EasyImage::Create($file)->adjustSmoothness(10);
echo EasyImage::Create($file)->colorMask("#FF000");
echo EasyImage::Create($file)->colorize("#FF0000");
echo EasyImage::Create($file)->colorFill(0, 0, "#FF0000");
echo EasyImage::Create($file)->mergeImages("myImage.psd");
Image Flip Constants
echo EasyImage::Create($file)->flip();
Image Mime Type Constants
echo EasyImage::Create($file)->convertTo(EasyImage::PDF);
Image Mime Type Constants
echo EasyImage::Create($file)->concat($newImage);
The class exposes several methods that allow you to get information about the image.
Returns: An array containing all unique colors in the image. If the EasyImage object is an animated GIF, will return an array of arrays for each layer.
$colors = EasyImage::Create($file)->getColors();
Returns: The GD image resource for the current EasyImage object. If it's an animated GIF, it will return an array containing the GD resource for each layer of the GIF.
$im = EasyImage::Create($file)->getImageResource();
Returns: A color that does not exist in the current image, or false if it's an animated GIF.
$color = EasyImage::Create($file)->getUniqueColor();
Returns: If the current image was autoCrop()'ed, it will return an array containing the offsets of the crop. If it's an animated GIF it will return an array for each layer/frame.
$offsets = EasyImage::Create($file)->getOffsets();
Returns: Returns the filepath for the original image used to create the current EasyImage object. This may or may not be a temporary file. If it's an animated GIF, will return an array with the filepath foe each layer.
$path = EasyImage::Create($file)->getFilepath();
Returns: The width of the current image.
$width = EasyImage::Create($file)->getWidth();
Returns: The height of the current image.
$height = EasyImage::Create($file)->getHeight();
Returns: The mime type of the current image.
$type = EasyImage::Create($file)->getMimeType();
Returns: Either the string "portrait" or "landscape".
$orientation = EasyImage::Create($file)->getOrientation();
Returns: The color index of a color at the given coordinates, or an array containing the color at that index of each frame of the GIF.
$color = EasyImage::Create($file)->getPixelColorIndex();
Returns: The pixel color for a given color index.
$color = EasyImage::Create($file)->getColorsFromIndex($index);
Returns: The GRBA color values of a given pixel.
$color = EasyImage::Create($file)->getPixelRGBA(0, 0);
Returns: The HEX color values of a given pixel.
$color = EasyImage::Create($file)->getPixelHexColor(0, 0);
Returns: An array of EasyImage objects for each layer of an animated GIF.
$Layers = EasyImage::Create($AnimatedGIF)->getGifSources();
Image Mime Type Constants
Returns: The base 64 data URL of the image.
$color = EasyImage::Create($file)->getBase64();
Image Mime Type Constants
$color = EasyImage::Create($file)->getString();
Returns: The image as a string.
$color = EasyImage::Create($file)->getCopy();
Returns: A copy of the current EasyImage object.
EasyImage provides some helper methods and utilities.
Returns: true if the two colors are the same, false else.
$sameColor = EasyImage::compareColors("#FFF", array(255, 255, 255));
Returns: 1 if the first color has a greater luma value than the second, else -1.
$brighterColor = EasyImage::compareLuma("#FFF", "#FF0);
Returns: An array of colors, sorted by luma value.
$colors = EasyImage::colorSortLuma($colors);
Returns: True if the image is an animated GIF, else false.
echo EasyImage::isAnimatedGif($file) ?
"Hoorah, animation!" :
"Boo, no animation." ;
Returns: An array of colors, sorted by color dominance value.
$colors = EasyImage::colorSort($colors);
Returns: Get the distance between any two given colors.
$distance = EasyImage::getColorDistance($color1, $color2);
Returns: The hex color string for the given RGB color array.
$distance = EasyImage::RGBToHex($color);
Returns: The RGB color array for the given hex color string.
$distance = EasyImage::hexToRGB($color);
Returns: An array of colors in the gradient.
$colors = EasyImage::gradientColors($color1, $color2);
EasyImage provides several built-in methods for outputting the image.
This is the most common type of output, and the easiest to use. To send the Image to the browser, simply echo or print it.
echo EasyImage::Create($file);
EasyImage::Create($image)->save("myImage.png");
EasyImage::Create($image)->download("yourImage.png");