1. Products
  2.   Image
  3.   PHP
  4.   WideImage

Open Source PHP API to Manipulate Images

PHP Library that enables Software programmers to Load, Resize  & Convert GIF, PNG, JPEG images with ease.

The WideImage is an open source object-oriented library that gives software developers the capability to manipulate images inside their own PHP applications. The library provides a simple way of loading, manipulating, and saving images in the most common image formats. The library supports features like resizing images, cropping, merging, writing a text with a shadow, converting to other formats, image cloning, applying a watermark on the image, and many more.

The library currently includes support for some of the most common image file formats which are natively supported by the GD extension on the server such as GIF, PNG, JPG, GD, GD2, WBMP, XBM, and XPM. It also supports BMP (read/write) and TGA (read-only). The library has included support for cross-format conversion. Developers can easily load an image in the format of their choice and then can save it in any other supported image file format.

The library uses GD extension to carry out most of the supported operations on images. The GD extension doesn’t support some functions and few are performing slow as they are coded in pure PHP. The WideImage team has worked hard to optimize the library code and has updated the GD functions to improve performance.

Previous Next

Getting Started with WideImage

It requires PHP 5.2+ with GD2 extension. You can easily install the WideImage library via PEAR. Please use the following command.

Install WideImage via PEAR

pear channel-discover pear.kozak.si
pear install kozak.si/WideImage 

Saving Images to Other Formats via PHP

The open source WideImage library has provided support for saving images to a file, directly to a browser, or can retrieve an image data as a string inside your own apps. To save to a file you need to pass the file name and its path as a parameter. While saving to JPEG or PNG, you can set the quality of the image for JPEG, and the compression level for PNG. While retrieving as a string, you can effortlessly capture image data and save it to a database or file. You can also save the image directly to the browser. You need to pass the image type parameter and it will be saved in the suggested format.

Save Image to a File via PHP API

include "path-to/WideImage.php";
//load Image
$image = WideImage::load("path-to/image.jpg");
// save to jpeg, quality=40
$img->saveToFile('image.jpg', 40);
// save to png, compression level = 6
$img->saveToFile('image.png', 6);

Loading Images via PHP API

The WideImage API allows software programmers to load an image of their choice with ease inside their own PHP application. The library provided several options for loading images, such as loading an image from a file, by providing a URL, from a binary string, or from a valid GD image resource. You need to provide a complete file path and image name. The binary string option is very useful when required to load images from a database.

Load & Edit Image via PHP

$font = '/resources/assets/NOVABOLD.otf';
  $image = WideImage::load('name');

  $canvas = $image->getCanvas();

  $canvas->useFont($font, 20, $image->allocateColor(255, 255, 255));          
  $canvas->writeText('center', 'top', 'I am ');

Image Resizing and Cropping

The free library WideImage has provided functionality for resizing or cropping images using PHP commands. You need to provide the new dimensions of the image. If one dimension is provided and the other isn’t specified (or null is given), the library smartly calculated it from the ratio of the other dimension. For operations like resizing and cropping where the coordinates are passed as parameters, the smart coordinates option is very useful.

Load & Edit Image via PHP

include "path-to/WideImage.php";
//load Image
$image = WideImage::load("path-to/image.jpg");
//Resize Image 
$resized = $image->resize(400, 300);
//Save Image