Image

Dynamic Image processor

7.4.1. Usage

use Cradle\Image\ImageHandler;
$image = ImageHandler::i('/path/to/image.jpg');

Once you are done modifying the image you can save the image to a file or simply echo out the image object like below.

header('Content-Type: image/jpg');
echo $image;

7.4.2. API


blur

Applies the selective blur filter. Blurs the image

Usage

$image->blur();

Parameters

Returns Cradle\Image\ImageHandler


brightness

Applies the brightness filter. Changes the brightness of the image.

Usage

$image->brightness(*number $level);

Parameters

  • *number $level - The level of brightness

Returns Cradle\Image\ImageHandler

Example

$image->brightness($level);

colorize

Applies the colorize filter. Like greyscale except you can specify the color.

Usage

$image->colorize(*number $red, *number $blue, *number $green, number $alpha);

Parameters

  • *number $red - The 255 value of red to use
  • *number $blue - The 255 value of blue to use
  • *number $green - The 255 value of green to use
  • number $alpha - The level of alpha transparency

Returns Cradle\Image\ImageHandler

Example

$image->colorize($red, $blue, $green);

contrast

Applies the contrast filter. Changes the contrast of the image.

Usage

$image->contrast(*number $level);

Parameters

  • *number $level - The level of contrast

Returns Cradle\Image\ImageHandler

Example

$image->contrast($level);

crop

Crops the image

Usage

$image->crop(int|null $width, int|null $height);

Parameters

  • int|null $width - The width; If null will use the original width
  • int|null $height - The height; If null will use the original height

Returns Cradle\Image\ImageHandler

Example

$image->crop();

edgedetect

Applies the edgedetect filter. Uses edge detection to highlight the edges in the image.

Usage

$image->edgedetect();

Parameters

Returns Cradle\Image\ImageHandler


emboss

Applies the emboss filter. Embosses the image.

Usage

$image->emboss();

Parameters

Returns Cradle\Image\ImageHandler


gaussianBlur

Applies the gaussian blur filter. Blurs the image using the Gaussian method.

Usage

$image->gaussianBlur();

Parameters

Returns Cradle\Image\ImageHandler


getDimensions

Returns the size of the image

Usage

$image->getDimensions();

Parameters

Returns array


getResource

Returns the resource for custom editing

Usage

$image->getResource();

Parameters

Returns [RESOURCE]


greyscale

Applies the greyscale filter. Converts the image into grayscale.

Usage

$image->greyscale();

Parameters

Returns Cradle\Image\ImageHandler


invert

Inverts the image.

Usage

$image->invert(bool $vertical);

Parameters

  • bool $vertical - If true invert vertical; if false invert horizontal

Returns Cradle\Image\ImageHandler

Example

$image->invert();

meanRemoval

Applies the mean removal filter. Uses mean removal to achieve a “sketchy” effect.

Usage

$image->meanRemoval();

Parameters

Returns Cradle\Image\ImageHandler


negative

Applies the greyscale filter. Reverses all colors of the image.

Usage

$image->negative();

Parameters

Returns Cradle\Image\ImageHandler


resize

Resizes the image. This is a version of scale but keeping it’s original aspect ratio

Usage

$image->resize(int|null $width, int|null $height);

Parameters

  • int|null $width - the width; if null will use the original width
  • int|null $height - the height; if null will use the original height

Returns Cradle\Image\ImageHandler

Example

$image->resize();

rotate

Rotates the image.

Usage

$image->rotate(*int $degree, int $background);

Parameters

  • *int $degree - The degree to rotate by
  • int $background - Background color code

Returns Cradle\Image\ImageHandler

Example

$image->rotate(123);

scale

Scales the image. If width or height is set to null a width or height will be auto determined based on the aspect ratio

Usage

$image->scale(int|null $width, int|null $height);

Parameters

  • int|null $width - The width; if null will use the original width
  • int|null $height - The height; if null will use the original height

Returns Cradle\Image\ImageHandler

Example

$image->scale();

setTransparency

Sets the background color to be transparent

Usage

$image->setTransparency();

Parameters

Returns Cradle\Image\ImageHandler


smooth

Applies the smooth filter. Makes the image smoother.

Usage

$image->smooth(*number $level);

Parameters

  • *number $level - The level of smoothness

Returns Cradle\Image\ImageHandler

Example

$image->smooth($level);

save

Saves the image data to a file

Usage

$image->save(*string $path, string|null $type);

Parameters

  • *string $path - The path to save to
  • string|null $type - The render type

Returns Cradle\Image\ImageHandler

Example

$image->save('foo');