Vesthelm Engine

2.1.1 User Guide

Image Class

The Image class provides image manipulation functionality.

Calling the Image Class

$Image = $this->Image;

Resizing an Image

$this->Image->img('Z:\tmp.jpg', 'uploads/test.jpg')
    ->resize(800, //image width
             600, //image height
            'proportional' //resize mode
            )
    ->save();

The first argument 'Z:\tmp.jpg' in img() function is temporary path from $_FILES['image']['tmp_name']. The second argument 'uploads/test.jpg' is the new path where new image will be saved.

The first argument '800' in resize() function is the image width. The second argument '600' is the image height. The third argument 'propotional' is the resizing mode.

Resizing modes:

proportional
stretch
fit

Watermarking an Image

$this->Image->img('Z:\tmp.jpg', 'uploads/test.jpg')
    ->watermark('path_to_watermark/watermark.png', //path to watermark image
                'bottom_right' //watermark position
    ->save();

The first argument 'Z:\tmp.jpg' in img() function is temporary path from $_FILES['image']['tmp_name']. The second argument 'uploads/test.jpg' is the new path where new image will be saved.

The first argument 'path_to_watermark/watermark.png' in watermark() function is the path to watermark image. The second argument 'bottom_right' is the watermark position.

Watermark positions:

top_left
top_center
top_right
middle_left
middle_center
middle_right
bottom_left
bottom_center
bottom_right