Toolkit Image

class Nos\Toolkit_Image

Toolkit for image manipulation.

Usage

To get a Toolkit_Image, use method getToolkitImage on classes supporting it.

Methods

Nos\Toolkit_Image::transformations($transformations)

Add multiple transformations to the image.

Parameters:
  • $transformations (array) –
    Transformations to add to the image.
    A transformation is an array where first value is the method name, others values are method arguments.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::crop($x1, $y1, $x2, $y2)

Add a crop transformation to the image.

Parameters:
  • $x1 (integer) – X-Coordinate based from the top-left corner.
  • $y1 (integer) – Y-Coordinate based from the top-left corner.
  • $x2 (integer) – X-Coordinate based from the bottom-right corner.
  • $y2 (integer) – Y-Coordinate based from the bottom-right corner.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::resize($width, $height, $keepar = true, $pad = false)

Resizes the image. If the width or height is null, it will resize retaining the original aspect ratio.

Parameters:
  • $width (integer) – The new width of the image.
  • $height (integer) – The new height of the image.
  • $keepar (boolean) – Defaults to true. If false, allows resizing without keeping aspect ratio.
  • $pad (boolean) – If set to true and $keepar is true, it will pad the image with the configured background color.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::shrink($max_width, $max_height)

Resizes the image only if too big

Parameters:
  • $max_width (integer) – The max width of the image.
  • $max_height (integer) – The max height of the image.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::crop_resize($width, $height)

Resizes the image. If the width or height is null, it will resize retaining the original aspect ratio.

Parameters:
  • $width (integer) – The new width of the image.
  • $height (integer) – The new height of the image.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::rotate($degrees)

Rotates the image

Parameters:
  • $degrees (integer) – The degrees to rotate, negatives integers allowed.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::flip($direction)

Creates a vertical / horizontal or both mirror image.

Parameters:
  • $direction (string) – vertical, horizontal, both
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::watermark($filename, $position, $padding = 5)

Adds a watermark to the image.

Parameters:
  • $filename (string) – The filename of the watermark file to use.
  • $position (string) – The position of the watermark, ex: bottom right, center center, top left
  • $padding (integer) – The spacing between the edge of the image.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::border($size, $color = null)

Adds a border to the image.

Parameters:
  • $size (integer) – The side of the border, in pixels.
  • $color (string) – A hexidecimal color.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::mask($maskimage)

Masks the image using the alpha channel of the image input.

Parameters:
  • $maskimage (string) – The location of the image to use as the mask
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::rounded($radius, $sides = null, $antialias = null)

Adds rounded corners to the image.

Parameters:
  • $radius (integer) –
  • $sides (integer) – Accepts any combination of tl tr bl br seperated by spaces, or null for all sides
  • $antialias (integer) – Sets the antialias range.
Returns:

The current Toolkit_Image for chaining.

Nos\Toolkit_Image::grayscale()

Turns the image into a grayscale version

Returns:The current Toolkit_Image for chaining.
Nos\Toolkit_Image::url($absolute = true)

Build and return the URL of the modify image

Parameters:
  • $absolute (bool) – Default true, if false return relative URL
Returns:

The URL of the modify image.

Nos\Toolkit_Image::sizes()
Returns:The dimensions of the modify image (an object containing width and height variables).
Nos\Toolkit_Image::html($params = array())

Creates an html image tag of the modify image

Sets width, height, alt attributes if not supplied.

Parameters:
  • $params (array) – The attributes array
Returns:

The image tag

Nos\Toolkit_Image::save()

Apply transformations of the Image_URL instance on a file and save it

Returns:The save file path
Nos\Toolkit_Image::parse($image_url)

Parse an existing modify URL and set transformations in queue. Check if the hash part of the URL match.

Parameters:
  • $image_url (string) – Modify URL of the image
Returns:

True or false if the hash part of the URL not match.

Example

<?php

$all_media_png = \Nos\Media\Model_Media::find('all', array(
    'where' => array(
        array('media_ext', 'png'),
    ),
)); // Get all images PNG in media

// Display all PNG, shrinked in 200x100, grayscale and rounded with a 5px radius, in a <img class="css_class" /> tag.
foreach ($all_media_png as $media) {
    echo $media->getToolkitImage()->shrink(200, 100)->grayscale()->rounded(5)->html(array(
        'class' => 'css_class',
    ));
}
Read the Docs v: elche
Versions
latest
stable
elche
dubrovka
chiba.2
chiba.1
Downloads
pdf
htmlzip
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.