php

SimpleImage 3.0

Back in 2011, I released the first version of SimpleImage for PHP — an open source project for working with images.

Today, version 3.0 has landed, and there's a lot to love about it.

Overview

Here's how it works at a glance:

try {
 // Create a new SimpleImage object
 $image = new claviska\SimpleImage();

 // Magic! ✨
 $image
  ->fromFile('image.jpg') // load image.png
  ->autoOrient() // adjust orientation based on exif data
  ->resize(320, 200) // resize to 320x200 pixels
  ->flip('x') // flip horizontally
  ->colorize('DarkBlue') // tint dark blue
  ->border('black', 10) // add a 10 pixel black border
  ->overlay('watermark.png', 'bottom right') // add a watermark image
  ->toFile('new-image.png', 'image/png') // convert to PNG and save a copy to new-image.png
  ->toScreen(); // output to the screen

 // And much more! 💪
} catch(Exception $err) {
 // Handle errors
 echo $err->getMessage();
}

Requirements

  • PHP 5.6+
  • GD extension

Features

  • Supports reading, writing, and converting GIF, JPEG, PNG, WEBP formats.
  • Reads and writes files and data URIs.
  • Manipulation: crop, resize, overlay/watermark, adding TTF text
  • Drawing: arc, border, dot, ellipse, line, polygon, rectangle, rounded rectangle
  • Filters: blur, brighten, colorize, contrast, darken, desaturate, edge detect, emboss, invert, pixelate, sepia, sketch
  • Utility methods: color adjustment, darken/lighten color, exif data, height/width, mime type, orientation
  • Color arguments can be passed in as any CSS color (e.g. `LightBlue`), a hex color, or an RGB(A) array.
  • Support for alpha-transparency (GIF, PNG, WEBP)
  • Chainable methods
  • Uses exceptions
  • Load with Composer or manually (just one file)

The readme has a list of changes from the 2.x version of SimpleImage.

Download

Download the latest version on GitHub.

esc