Represents an image item attached to a page, typically via an Image Fieldtype.

Pageimage objects are usually contained by a Pageimages object, which is a type of Pagefiles and WireArray. In addition to the methods and properties below, you'll also want to look at Pagefile which this class inherits several important methods and properties from.

// Example of outputting a thumbnail gallery of Pageimage objects
foreach($page->images as $image) {
  // $image and $thumb are both Pageimage objects
  $thumb = $image->size(200, 200);    
  echo "<a href='$image->url'>"; 
  echo "<img src='$thumb->url' alt='$image->description' />";
  echo "</a>";
}

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Pageimage class also inherits all the methods and properties of: Pagefile, WireData and Wire.

Common / Resize and crop / Variations / Other

Common

Name Return Summary  
Pageimage::basename string
Pageimage::filename() string Returns the full disk path to the image file
Can also be used as property: Pageimage::filename
Pageimage::height() int or Pageimage Return the height of this image OR return an image sized with a given height (and proportional width).
Can also be used as property: Pageimage::height
Pageimage::size(int $width, int $height) Pageimage Return an image (Pageimage) sized/cropped to the specified dimensions.
Pageimage::url() string Return the web accessible URL to this image file
Can also be used as property: Pageimage::url
Pageimage::width() int or Pageimage Return the width of this image OR return an image sized with a given width (and proportional height).
Can also be used as property: Pageimage::width

Resize and crop

Name Return Summary  
Pageimage::crop(int $x, int $y, int $width, int $height) Pageimage Create a crop and return it as a new Pageimage.
Pageimage::error string Last image resizing error message, when applicable.
Pageimage::height() int or Pageimage Return the height of this image OR return an image sized with a given height (and proportional width).
Can also be used as property: Pageimage::height
Pageimage::maxHeight(int $n) Pageimage Return an image no larger than the given height.
Pageimage::maxSize(int $width, int $height) Pageimage Return an image no larger than the given width and height
Pageimage::maxWidth(int $n) Pageimage Return an image no larger than the given width.
Pageimage::size(int $width, int $height) Pageimage Return an image (Pageimage) sized/cropped to the specified dimensions.
Pageimage::width() int or Pageimage Return the width of this image OR return an image sized with a given width (and proportional height).
Can also be used as property: Pageimage::width

Variations

A variation refers to an image that is based upon another (like a resized or cropped version for example).

Name Return Summary  
Pageimage::getOriginal() Pageimage or null If this image is a variation, return the original, otherwise return null.
Pageimage::getVariations() Pageimages or array Get all size variations of this image
Pageimage::isVariation(string $basename) bool or array Given a file name (basename), return array of info if this is a variation for this instance’s file, or false if not.
Pageimage::original Pageimage Reference to original $image, if this is a resized version.
Pageimage::rebuildVariations() array Rebuilds variations of this image
Pageimage::removeVariations() $this Delete all the alternate sizes associated with this Pageimage
Pageimage::setOriginal(Pageimage $image) $this Identify this Pageimage as a variation, by setting the Pageimage it was resized from.

Other

Name Return Summary  
Pageimage::suffix() array or bool Returns array of suffixes for this file, or true/false if this file has the given suffix.

Additional methods and properties

In addition to the methods and properties above, Pageimage also inherits the methods and properties of these classes: