To facilitate most frequent operations with image files (resizing, cropping, rotation, etc.), the framework offers waImage class. This class utilizes functions provided by a standard image processing extension (library) for PHP: GD or Imagick. The currently used extension is determined at the class instance generation stage. By default the GD library is used. Note: Animated GIF images can be processed inly by means of the Imagick extension.

Examples of creation of a waImage class instance from an image file:

// GD
$img = waImage::factory("/tmp/1.jpg");
$img = waImage::factory("/tmp/1.jpg", waImage::Gd);
//Imagick $img = waImage::factory("/tmp/1.jpg", waImage::Imagick);

Image resizing

// resizing to 100 pixels by the larger dimension, i.e. to inscribing in a rectangle
$img->resize(100, 100);

// resizing to 100*100 pixels without preserving original proportions
$img->resize(100, 100, waImage::NONE);

// inscribe in a rectangle
$img->resize(100, 200, waImage::AUTO);

// resizing to 100 pixels by the smaller dimension, i.e. to completely fill a rectangle
$img->resize(100, 100, waImage::INVERSE);

// resizing to 100 pixels by the smaller dimension
$img->resize(100, 100, waImage::WIDTH);

// equal to the previous example
$img->resize(100, false);

Image cropping

// crop a 100*100 pixels large square in the middle of an image

// crop a square from the top-left image corner
$img->crop(100,100, 0, 0);

// crop a square in the left middle
$img->crop(100,100, 0 , waImage::CENTER);

// crop a square from the bottom-right image corner
$img->crop(100,100, waImage::BOTTOM , waImage::BOTTOM);


$img->rotate(270);  // (-360;360)

Image sharpness

// this method accepts a value from 1 up to 100  as an argument,
// which denotes the target image quality as percentage of the original image quality


Saving a modified image to a file


Example of creating a 100*100 pixels large image thumbnail cropped from the center of the original image:

waImage::factory("/tmp/1.jpg")->resize(100, 100, waImage::INVERSE)
    ->crop(100,100)   // calling the method without arguments: cropping from the center