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

Show “Pageimage”             Show Arguments        

Common

NameReturnSummary 
Pageimage::__construct($pagefiles, string $filename)
(nothing)Construct a new Pageimage
Pageimage::basename string
Pageimage::filename()
stringReturns the full disk path to the image file
Can also be used as property: Pageimage::filename
Pageimage::height()
int or PageimageReturn 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)
PageimageReturn an image (Pageimage) sized/cropped to the specified dimensions.
Pageimage::url()
stringReturn the web accessible URL to this image file
Can also be used as property: Pageimage::url
Pageimage::width()
int or PageimageReturn 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

NameReturnSummary 
Pageimage::crop(int $x, int $y, int $width, int $height)
PageimageCreate a crop and return it as a new Pageimage.
Pageimage::error string Last image resizing error message, when applicable.
Pageimage::height()
int or PageimageReturn 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)
PageimageReturn an image no larger than the given height.
Pageimage::maxSize(int $width, int $height)
PageimageReturn an image no larger than the given width and height
Pageimage::maxWidth(int $n)
PageimageReturn an image no larger than the given width.
Pageimage::size(int $width, int $height)
PageimageReturn an image (Pageimage) sized/cropped to the specified dimensions.
Pageimage::width()
int or PageimageReturn 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).

NameReturnSummary 
Pageimage::getOriginal()
Pageimage or nullIf this image is a variation, return the original, otherwise return null.
Pageimage::getVariations()
Pageimages or arrayGet all size variations of this image
Pageimage::isVariation(string $basename)
bool or arrayGiven 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()
arrayRebuilds variations of this image
Pageimage::removeVariations()
$thisDelete all the alternate sizes associated with this Pageimage
Pageimage::setOriginal(Pageimage $image)
$thisIdentify this Pageimage as a variation, by setting the Pageimage it was resized from.

Other

NameReturnSummary 
Pageimage::suffix()
array or boolReturns 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:

API reference based on ProcessWire core version 3.0.62