waImage

Image management

Contents...

To begin working with an image, create an instance of this class by passing the file to path to its constructor; e.g.:

$image = new waImage($path);
$image->rotate(90);

Methods

public function crop ($width, $height, $offset_x = self::CENTER, $offset_y = self::CENTER, $deny_exceed_original_sizes = true)

Crops specified image part.

Parameters

Example

$image = waImage::factory($image_path);
$image->crop(100, 100);

public static function factory ($file, $adapter = false)

Returns an instance of class waImage for processing specified image file.

Parameters

Example

$image = waImage::factory($image_path);
//here you can call public methods of the <code>$image</code> object to process the specified image

public function filter ($type, $params = array())

Applies a graphical filter to an image.

Parameters

Example

$image = waImage::factory($image_path);
$image->filter('CONTRAST', array('level' => 15));

public function getExt()

Returns name extension of a graphical file corresponding to its type.

Example

$image = new waImage($jpeg_image_path);
echo $image->getExt();

Result

jpg

public function resize ($width = null, $height = null, $master = null, $deny_exceed_original_sizes = true)

Resizes an image.

Parameters

Example

$image = waImage::factory($image_path);
$image->resize(100, 150, 'HEIGHT');

public function rotate ($degrees)

Rotates an image.

Parameters

Example

$image = waImage::factory($image_path);
$image->rotate(90);

public function save ($file = null, $quality = 100)

Save an image with specified quality level to a file.

Parameters

Example

$image = waImage::factory($image_path);
// here you can call image processing methods
// and then save the modified image to a file
$image->save(null, 85);

public function sharpen ($amount)

Applies a sharpening filter to an image.

Parameters

Example

$image = waImage::factory($image_path);
$image->sharpen(15);

public function watermark ($options)

Adds a watermark to an image.

Parameters

Example

$image = waImage::factory($image_path);
$options = array(
    'watermark'        => 'watermark text',
    'opacity'          => 0.5,
    'align'            => 'ALIGN_BOTTOM_RIGHT',
    'font_size'        => '10',
    'font_color'       => 'ffffff',
    'text_orientation' => 'VERTICAL',
);
// below is an example of watermark parameters if an image file is used instead of simple text
/*
$options = array(
    'watermark' => new waImage($watermark_image_path),
    'opacity'   => 0.3,
    'align'     => 'ALIGN_BOTTOM_RIGHT',
);
*/
$image->watermark($options);