Image - adampatterson/Dingo-Framework GitHub Wiki

Overview

The Image helper simplifies basic image manipulation. To load the Image helper manually you may do this:

load::library('image');

Open

$image = new image('stats.jpg');

The above opens up stats.jpg and creates a new object for manipulating that image.

NOTE: Working with large images in PHP can use up a lot of memory, so if you are going to be working with images make sure that php.ini is set to allocate enough memory to do so.

###Close Removes image object from memory. This is very important and should always be used when done working with images!

$image->close();

Type

Changes the type of an image. Supported values are jpg, gif, and png.

$image->type('jpg');

Resize

Resizes an image to the specified width and height.

$image->resize(250,200);

If you provide NULL for width or height then the image will be scaled proportionately to the given width or height.

$image->resize(250,NULL);

Dynamic Resize

Resizes and crops an image to fit a specified width and height without distorting the image.

$image->dynamic_resize(250,200);

Crop

Crops an image. First two arguments define the crop offset relative to the top left corner of the image.

$image->crop(0,0,250,200);

Zone Crop

Crops an image from a specified side, corner, or from the center.

The first two arguments are the width and height of the crop zone and the third argument is the crop zone. Possible zones include:

  • top-left
  • top
  • top-right
  • right
  • bottom-right
  • bottom
  • bottom-left
  • left
  • center

$image->zone_crop(250,200,'center');

Rotate

Rotates an image a specified number of degrees.

$image->rotate(90);

Save

Saves an image. Must be used to save any changes made to your image.

// do something...
$image->save('new.jpg');```

### Show
Displays image including setting correct HTTP headers.

    $image = new image('stats.jpg');
    // possibly do something...
    $image->show();
    
### Width And Height
You can access the width and height measurements of the image to use in any calculations you may want to do.

    echo $image->width;
    echo $image->height;

### Quality
Sets the % of quality that GIF and JPEG images will be saved or displayed with. If not set Dingo uses 100% quality.

`$image->quality(85);`

###Compression
Sets the amount of compression PNG images will be saved or displayed with. Accepts a value between 0 and 9 with a default value of 4.

`$image->compression(6);`

> Note: If you set compression too low, your PNG images will become extremely large in size.