About AvbImage

Image Manipulation Module for ProcessWire

Category Photo/Video/Audio
Modules that perform some function related to media such as photos and audio/video.
Release StateBeta
Close to stable, but users are advised to be cautious and test thoroughly.*
Module Version0.0.4
Class NameAvbImage
Compatibility2.5, 2.6, 2.7
Date AddedOctober 28, 2015
Last UpdatedDecember 10, 2015
Recommended ByNew recommendations may take up to 1 day to appear.


This module's files should be placed in /site/modules/AvbImage/
How to install or uninstall modules


AvbImage - Image Manipulator Module for ProcessWire

This module using Intervention Image PHP image handling and manipulation library.

Big thanks to Oliver Vogel

Module Author


  • ProcessWire >= 2.5.11
  • PHP >=5.4
  • Fileinfo Extension

Supported Image Libraries

  • GD Library (>=2.0)
  • Imagick PHP extension (>=6.5.7)

Methods List

Resizing Images

Adjusting Images

Applying Effects


Retrieving Information


Resizing Images


Resizes current image based on given width and/or height. Tocontraint the resize command, pass an optional Closure callback asthird parameter.

$resized = $page->images()->first()->image()->resize(500, 300);
echo "<img src='{$resized->encode('data-url')}' />";

Resizes the current image to new width, constraining aspect ratio.Pass an optional Closure callback as third parameter, to applyadditional constraints like preventing possible upsizing.

$widen = $page->images()->first()->image()->widen(500);
echo "<img src='{$widen->encode('data-url')}' />";

Resizes the current image to new height, constraining aspect ratio.Pass an optional Closure callback as third parameter, to applyadditional constraints like preventing possible upsizing.

$heighten = $page->images()->first()->image()->heighten(300);
echo "<img src='{$heighten->encode('data-url')}' />";

Combine cropping and resizing to format image in a smart way. Themethod will find the best fitting aspect ratio of your given width and height on the current image automatically, cut it out and resize it tothe given dimension. You may pass an optional Closure callback asthird parameter, to prevent possible upsizing and a custom position ofthe cutout as fourth parameter.

$fit = $page->images()->first()->image()->fit(600, 360);
echo "<img src='{$fit->encode('data-url')}' />";

Factory method to create a new empty image instance with given width and height.You can define a background-color optionally. By default the canvas background is transparent.

$canvas = $page->images()->first()->image()->canvas(32, 32, '#ff0000')
echo "<img src='{$canvas->encode('data-url')}' />";

Resize the boundaries of the current image to given width and height.An anchor can be defined to determine from what point of the image theresizing is going to happen. Set the mode to relative to add orsubtract the given width or height to the actual image dimensions. You can also pass a background color for the emerging area of the image.

$resizeCanvas = $page->images()->first()->image()->resizeCanvas(1280, 720, 'center', false, 'ff00ff');
echo "<img src='{$resizeCanvas->encode('data-url')}' />";


Cut out a rectangular part of the current image with given width and height. Define optional x, y coordinates to movethe top-left corner of the cutout to a certain position.

$crop = $page->images()->first()->image()->crop(100, 100, 25, 25);
echo "<img src='{$crop->encode('data-url')}' />";

Trim away image space in given color. Define an optional base to picka color at a certain position and borders that should be trimmed away.You can also set an optional tolerance level, to trim similar colorsand add a feathering border around the trimed image.

$trim = $page->images()->first()->image()->trim('transparent', array('top', 'bottom'));
echo "<img src='{$trim->encode('data-url')}' />";

Adjusting Images


Performs a gamma correction operation on the current image.

$gamma = $page->images()->first()->image()->gamma(1.6);
echo "<img src='{$gamma->encode('data-url')}' />";

Changes the brightness of the current image by the given level. Usevalues between -100 for min. brightness 0 for no change and +100 for max. brightness.

$brightness = $page->images()->first()->image()->brightness(35);
echo "<img src='{$brightness->encode('data-url')}' />";


Changes the contrast of the current image by the given level. Usevalues between -100 for min. contrast 0 for no change and +100 for max. contrast.

$contrast = $page->images()->first()->image()->contrast(65);
echo "<img src='{$contrast->encode('data-url')}' />";

Change the RGB color values of the current image on the given channels red, green and blue. The input values are normalized so you have toinclude parameters from 100 for maximum color value 0 for no changeand -100 to take out all the certain color on the image.

$colorize = $page->images()->first()->image()->colorize(0, 30, 0);
echo "<img src='{$colorize->encode('data-url')}' />";

Turns image into a greyscale version.

$greyscale = $page->images()->first()->image()->greyscale();
echo "<img src='{$greyscale->encode('data-url')}' />";

Reverses all colors of the current image.

$invert = $page->images()->first()->image()->invert();
echo "<img src='{$invert->encode('data-url')}' />";

Apply a given image source as alpha mask to the current image tochange current opacity. Mask will be resized to the current image size. By default a greyscale version of the mask is converted to alpha values, but you can set mask_with_alpha to apply the actual alphachannel. Any transparency values of the current image will be maintained.

$mask1 = $page->images()->first()->image()->mask('public/mask.png');
echo "<img src='{$mask1->encode('data-url')}' />";
$mask2 = $page->images()->first()->image()->mask('public/alpha.png', true);
echo "<img src='{$mask2->encode('data-url')}' />";

Mirror the current image horizontally or vertically by specifying themode.

$flip = $page->images()->first()->image()->flip('v');
echo "<img src='{$flip->encode('data-url')}' />";

Set the opacity in percent of the current image ranging from 100%for opaque and 0% for full transparency.

Note: Performance intensive on larger images. Use with care.

$opacity = $page->images()->first()->image()->opacity(50);
echo "<img src='{$opacity->encode('data-url')}' />";

Fill current image with given color or another image used as tile for filling.Pass optional x, y coordinates to start at a certain point.

If a certain position is defined, the color at that point on the originalimage is used to perform a flood fill. If no x,y coordinates are passed, the whole picture is filled no matter what is beneath.

$fill = $page->images()->first()->image()->fill('#ff00ff', 0, 0);
echo "<img src='{$fill->encode('data-url')}' />";

Paste a given image source over the current image with an optional positionand a offset coordinate. This method can be used to apply another image as watermark because the transparency values are maintained.

$insert = $page->images()->first()->image()->insert('watermark.png', 'bottom-right', 10, 10);
echo "<img src='{$insert->encode('data-url')}' />";

Applying Effects


Not worked on this !


Applies a pixelation effect to the current image with a given size ofpixels.

$pixelate = $page->images()->first()->image()->pixelate(12);
echo "<img src='{$pixelate->encode('data-url')}' />";

Rotate the current image counter-clockwise by a given angle.Optionally define a background color for the uncovered zone after the rotation.

// rotate image 45 degrees clockwise
$rotate = $page->images()->first()->image()->rotate(-45);
echo "<img src='{$rotate->encode('data-url')}' />";

Apply a gaussian blur filter with a optional amount on the currentimage. Use values between 0 and 100.

Note: Performance intensive on larger amounts of blur with GD driver. Use with care.

// apply slight blur filter
$blur1 = $page->images()->first()->image()->blur();
echo "<img src='{$blur1->encode('data-url')}' />";
// apply stronger blur
$blur2 = $page->images()->first()->image()->blur(15);
echo "<img src='{$blur2->encode('data-url')}' />";

Sharpen current image with an optional amount. Use values between 0 and 100.

$sharpen = $page->images()->first()->image()->sharpen(15);
echo "<img src='{$sharpen->encode('data-url')}' />";



Write a text string to the current image at an optional x,y basepointposition. You can define more details like font-size, font-file andalignment via a callback as the fourth parameter.

$text1 = $page->images()->first()->image()->text('The quick brown fox jumps over the lazy dog.', 120, 100);
echo "<img src='{$text1->encode('data-url')}' />";
$text2 = $page->images()->first()->image()->text('foo', 0, 0, function($font) {
echo "<img src='{$text2->encode('data-url')}' />";

Draw a single pixel in given color on x, y position.

$pixel = $page->images()->first()->image()->pixel('#ff0000', 64, 64);
echo "<img src='{$pixel->encode('data-url')}' />";

Draw a line from x, y point 1* to **x, y point 2 on current image. Define color and/or width of line in an optional Closure callback.

$line = $page->images()->first()->image()->line(10, 10, 195, 195, function ($draw) {
echo "<img src='{$line->encode('data-url')}' />";

Draw a colored rectangle on current image with top-left corner on x,y point 1 and bottom-right corner at x,y point 2. Define the overallappearance of the shape by passing a Closure callback as an optionalparameter.

// draw an empty rectangle border
$rectangle1 = $page->images()->first()->image()->rectangle(10, 10, 190, 190);
echo "<img src='{$rectangle1->encode('data-url')}' />";
// draw filled red rectangle
$rectangle2 = $page->images()->first()->image()->rectangle(5, 5, 195, 195, function ($draw) {
echo "<img src='{$rectangle2->encode('data-url')}' />";

Draw a circle at given x, y, coordinates with given diameter.You can define the appearance of the circle by an optional closurecallback.

$circle1 = $page->images()->first()->image()->circle(100, 50, 50, function ($draw) {
echo "<img src='{$circle1->encode('data-url')}' />";
$circle2 = $page->images()->first()->image()->circle(10, 100, 100, function ($draw) {
    $draw->border(1, '#f00');
echo "<img src='{$circle2->encode('data-url')}' />";

Draw a colored ellipse at given x, y, coordinates. You candefine width and height and set the appearance of thecircle by an optional closure callback.

$ellipse1 = $page->images()->first()->image()->ellipse(25, 30, 50, 50, function ($draw) {
echo "<img src='{$ellipse1->encode('data-url')}' />";
$ellipse2 = $page->images()->first()->image()->ellipse(60, 120, 100, 100, function ($draw) {
    $draw->border(1, '#ff0000');
echo "<img src='{$ellipse2->encode('data-url')}' />";

Draw a colored polygon with given points. You can definethe appearance of the polygon by an optional closure callback.

// define polygon points
$points = array(
    40,  50,  // Point 1 (x, y)
    20,  240, // Point 2 (x, y)
    60,  60,  // Point 3 (x, y)
    240, 20,  // Point 4 (x, y)
    50,  40,  // Point 5 (x, y)
    10,  10   // Point 6 (x, y)
// draw a filled blue polygon with red border
$polygon = $page->images()->first()->image()->polygon($points, function ($draw) {
    $draw->border(1, '#ff0000');
echo "<img src='{$polygon->encode('data-url')}' />";

Retrieving Information


Encodes the current image in given format and given image quality.

// encode png image as jpg
$pngToJpg = $page->image()->first()->image()->encode('jpg', 75);
echo "<img src='{$pngToJpg->encode('data-url')}' />";
// encode image as data-url
echo $page->image()->first()->image()->encode('data-url');

Returns the width in pixels of the current image.

echo $page->image()->first()->image()->width();

Returns the height in pixels of the current image.

echo $page->images()->first()->image()->height();

Read MIME Type of current image instance, if it's already defined.

echo $page->image()->first()->image()->mime();

Read Exif meta data from current image. Image object must beinstantiated from file path.

Note: PHP must be compiled in with --enable-exif to use this method. Windows users must also have the mbstring extension enabled.

$exif = $page->images()->first()->image()->exif();
echo '<pre>' . print_r($exif, true) . '</pre>';

Read IPTC meta data from current image.

$iptc = $page->images()->first()->image()->iptc();
echo '<pre>' . print_r($iptc, true) . '</pre>';

Backups current image state as fallback for reset method under an optional name.Overwrites older state on every call, unless a different name is passed.

$img = $page->images()->first()->image();
// fill image with color
// backup image with colored background
// fill image with tiled image
// return to colored background

Frees memory associated with the current image instance before the PHP script ends.Normally resources are destroyed automatically after the script is finished.

$img = $page->images()->first()->image();
// perform some modifications and destroy resource
$img->resize(320, 240);

Save the current state of the image object in filesystem. Define optionally a certain pathwhere the image should be saved. You can also optionally set the quality of the image file as second parameter.

The image type will be defined by the file extension. For example if you pass foo.jpg theimage will be saved as a JPG file. If there is no extension available, the library will first try to use the MIME type of the image to define the encoding, if this also fails the image will be encoded as JPEG.

Furthermore the image will always be saved in RGB color mode without an embeded color profile.

$img = $page->images()->first()->image();
$greyscale = $img->greyscale()->save();
echo "<img src='{$greyscale->url}' />";
// save file medium quality
$quality = $img->greyscale()->save(null, 60);
echo "<img src='{$greyscale->url}' />";
// save file as png with medium quality
$img->save('public/bar.png', 60);
// save the same file as jpeg with default quality

Gets the file size for the current image, if instance is initiated from an actual file.

$img = $page->images()->first()->image();
// get file size
$size = $img->filesize();
echo $size;

Returns the current image in core format of the particular driver. If you're using GD,you will get the the current GD resource as return value. If you have setup the Imagick driver, the method will return the current image information as an Imagick object.

$img = $page->images()->first()->image();
// get Imagick instance
$imagick = $img->getCore();
// apply Imagick function
$imagick->embossImage(0, 1);

Resets all of the modifications to a state saved previously by backup under an optional name.

$img = $page->images()->first()->image();
// backup status
// perform some modifications
$img->resize(320, 240);
// reset image (return to backup state)
// perform other modifications
$img->resize(640, 480);

Sends HTTP response with current image in given format and quality.

$img = $page->images()->first()->image();
// send HTTP header and output image data
echo $img->response();

Pick a color at point x, y out of current image and return in optional given format.

$img = $page->images()->first()->image();
// pick a color at position as array
$arraycolor = $img->pickColor(100, 100);
// pick a color at position as integer
$intcolor = $img->pickColor(100, 100, 'int');
// pick a color at position and format it as hex string
$hexcolor = $img->pickColor(100, 100, 'hex');

Determine whether an image should be encoded in interlaced or standard mode by toggling interlace mode with a boolean parameter. If an JPEG image is set interlaced the imagewill be processed as a progressive JPEG.

$img = $page->images()->first()->image();
// enable interlacing
// save image interlaced
$img = $page->images()->first()->image();
// disable interlacing
// save image in standard mode

Method converts the existing colors of the current image into a color table with a givenmaximum count of colors. The function preserves as much alpha channel information as possible and blends transarent pixels against a optional matte color.

$img = $page->images()->first()->image();
// limit colors to 255 (PNG-8) blending transparency against orange
$img->limitColors(255, '#ff9900');

This method reads the EXIF image profile setting 'Orientation' and performs arotation on the image to display the image correctly.

Note: PHP must be compiled in with --enable-exif to use this method. Windows users must also have the mbstring extension enabled.

$img = $page->images()->first()->image();


No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.