Documentation

Image
in package

Manipulate images using standard methods such as resize, crop, rotate, etc.

This class must be re-initialized for every image you wish to manipulate.

Table of Contents

Constants

AUTO  : mixed = 2
HEIGHT  : mixed = 3
HORIZONTAL  : mixed = 5
NONE  : mixed = 1
VERTICAL  : mixed = 6
WIDTH  : mixed = 4

Properties

$allowed_types  : mixed
$ext  : string
$file  : string
$height  : int
$mime  : string
$type  : string
$width  : int
$actions  : array<string|int, mixed>
Driver actions
$config  : array<string|int, mixed>
$driver  : ImageDriver
Driver instance
$image  : array<string|int, mixed>
Reference to the current image filename

Methods

__construct()  : void
Creates a new image editor instance.
__get()  : mixed
Handles retrieval of pre-save image properties
addText()  : Image
Adds text to the base of an image, e.g. for copyright credit
base64()  : mixed
Generate a base64-encoded PNG image, e.g. for an <img src="data:image/png;base64,..."> tag
calcResizeDims()  : array<string|int, mixed>
Calculates dimensions to be generated by a resize
crop()  : self
Crop an image to a specific width and height. You may also set the top and left offset.
factory()  : Image
Creates a new Image instance and returns it.
flip()  : int
Flip an image horizontally or vertically.
quality()  : int
Change the quality of an image.
render()  : bool
Output the image to the browser.
resize()  : self
Resize an image to a specific width and height. By default, Kohana will maintain the aspect ratio using the width as the master dimension. If you wish to use height as master dim, set $image->master_dim = Image::HEIGHT This method is chainable.
rotate()  : int
Allows rotation of an image by 180 degrees clockwise or counter clockwise.
save()  : bool
Save the image to a new image or overwrite this image.
sharpen()  : int
Sharpen an image.
validSize()  : bool
Sanitize a given value type.

Constants

HEIGHT

public mixed HEIGHT = 3

HORIZONTAL

public mixed HORIZONTAL = 5

VERTICAL

public mixed VERTICAL = 6

WIDTH

public mixed WIDTH = 4

Properties

$allowed_types

public static mixed $allowed_types = array(IMAGETYPE_GIF => 'gif', IMAGETYPE_JPEG => 'jpg', IMAGETYPE_PNG => 'png', IMAGETYPE_TIFF_II => 'tiff', IMAGETYPE_TIFF_MM => 'tiff', IMAGETYPE_WEBP => 'webp')

$actions

Driver actions

protected array<string|int, mixed> $actions = []

$config

protected array<string|int, mixed> $config = []

$image

Reference to the current image filename

protected array<string|int, mixed> $image = []

Methods

__construct()

Creates a new image editor instance.

public __construct(string $image[, array<string|int, mixed>|null $config = null ]) : void
Parameters
$image : string

filename of image

$config : array<string|int, mixed>|null = null

non-default configurations

Tags
throws
Kohana_Exception

__get()

Handles retrieval of pre-save image properties

public __get(string $property) : mixed
Parameters
$property : string

name

addText()

Adds text to the base of an image, e.g. for copyright credit

public addText(string $text) : Image
Parameters
$text : string

The text to add to the image

Return values
Image —

self, for chaining

base64()

Generate a base64-encoded PNG image, e.g. for an <img src="data:image/png;base64,..."> tag

public static base64(mixed $file_path[, ImageTransform $transform = null ]) : mixed
Parameters
$file_path : mixed

Path to the original file

$transform : ImageTransform = null

Optional transform to apply to the image

Tags
throws
Kohana_Exception

calcResizeDims()

Calculates dimensions to be generated by a resize

public calcResizeDims(int $width, int $height, int $master) : array<string|int, mixed>
Parameters
$width : int

Width in pixels

$height : int

Height in pixels

$master : int

Master dimension, e.g. Image::HEIGHT for a portrait image, Image::AUTO for any kind of image

Return values
array<string|int, mixed> —

[0 => width, 1 => height]

crop()

Crop an image to a specific width and height. You may also set the top and left offset.

public crop(int|null $width, int|null $height[, int|string $top = 'center' ][, int|string $left = 'center' ]) : self

This method is chainable.

Parameters
$width : int|null
$height : int|null
$top : int|string = 'center'

offset, pixel value or one of: top, center, bottom

$left : int|string = 'center'

offset, pixel value or one of: left, center, right

Tags
throws
Kohana_Exception
Return values
self

factory()

Creates a new Image instance and returns it.

public static factory(string $image[, array<string|int, mixed>|null $config = null ]) : Image
Parameters
$image : string

filename of image

$config : array<string|int, mixed>|null = null

Config array for non-default configurations

Return values
Image —

object

flip()

Flip an image horizontally or vertically.

public flip(mixed $direction) : int
Parameters
$direction : mixed
Tags
throws
Kohana_Exception
Return values
int —

$direction direction

quality()

Change the quality of an image.

public quality(mixed $amount) : int
Parameters
$amount : mixed
Return values
int —

$amount quality as a percentage

render()

Output the image to the browser.

public render([bool $keep_actions = false ]) : bool
Parameters
$keep_actions : bool = false

keep or discard image process actions

Return values
bool

resize()

Resize an image to a specific width and height. By default, Kohana will maintain the aspect ratio using the width as the master dimension. If you wish to use height as master dim, set $image->master_dim = Image::HEIGHT This method is chainable.

public resize(int|null $width, int|null $height[, int|null $master = null ]) : self
Parameters
$width : int|null
$height : int|null
$master : int|null = null

one of: Image::NONE, Image::AUTO, Image::WIDTH, Image::HEIGHT

Tags
throws
Kohana_Exception
Return values
self

rotate()

Allows rotation of an image by 180 degrees clockwise or counter clockwise.

public rotate(mixed $degrees) : int
Parameters
$degrees : mixed
Return values
int —

$degrees

save()

Save the image to a new image or overwrite this image.

public save([string|false $new_image = false ][, int|false $chmod = 0644 ][, bool $keep_actions = false ]) : bool
Parameters
$new_image : string|false = false

new image filename

$chmod : int|false = 0644

File permissions for new image

$keep_actions : bool = false

keep or discard image process actions

Tags
throws
Kohana_Exception
Return values
bool

sharpen()

Sharpen an image.

public sharpen(mixed $amount) : int
Parameters
$amount : mixed
Return values
int —

$amount amount to sharpen, usually ~20 is ideal

validSize()

Sanitize a given value type.

protected validSize(string $type, mixed &$value) : bool
Parameters
$type : string

of property

$value : mixed

property value

Return values
bool
On this page

Search results