Pageimage class

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.

Show class?             Show args?        

Common

NameReturnSummary 
Pageimage::__construct($pagefiles, string $filename)
(nothing)Construct a new Pageimage 
Pageimage::alt string Convenient alias for the 'description' property, unless overridden (since 3.0.125). 
Pageimage::basename string Returns the filename without the path. 
Pageimage::debugInfo PageimageDebugInfo 
Pageimage::description string Value of the file’s description field (string), if enabled. Note you can also set this property directly. 
Pageimage::ext string File’s extension (i.e. last 3 or so characters) 
Pageimage::filename()
stringReturns the full disk path to the image file
Can also be used as property: Pageimage::filename
 
Pageimage::filesize int File size (number of bytes). 
Pageimage::filesizeStr string File size as a formatted string, i.e. “123 Kb”. 
Pageimage::focusStr string Readable string containing focus information. 
Pageimage::getDebugInfo()
array object stringVerbose debug info (via 
Pageimage::hasFocus bool Does this image have custom focus settings? (i.e. $focus['default'] == true) 
Pageimage::hash string Get a unique hash (for the page) representing this Pagefile. 
Pageimage::height()
int 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::httpUrl string URL to the file on the server including scheme and hostname. 
Pageimage::name string Returns the filename without the path, same as the "basename" property. 
Pageimage::render()
stringRender markup for this image (optionally using a provided markup template string and/or image size options)
Pageimage::size(int $width, int $height)
PageimageReturn an image (Pageimage) sized/cropped to the specified dimensions. 
Pageimage::src string Convenient alias for the 'url' property, unless overridden (since 3.0.125). 
Pageimage::suffixStr string String of file suffix(es) separated by comma. 
Pageimage::url()
stringReturn the web accessible URL to this image file
Can also be used as property: Pageimage::url
 
Pageimage::webp()
PagefileExtraGet WebP "extra" version of this Pageimage
Can also be used as property: Pageimage::webp
 
Pageimage::width()
int 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 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 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 nullIf this image is a variation, return the original, otherwise return null. 
Pageimage::getVariations()
Pageimages arrayGet all size variations of this image 
Pageimage::isVariation(string $basename)
bool string 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()
this arrayDelete 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::HTTPURL string Same as the cache-busting uppercase “URL” property, but includes scheme and hostname.  
Pageimage::URL string Same as $url property but with browser cache busting query string appended.  
Pageimage::field Field The Field object that this file is part of.  
Pageimage::focus()
array bool PageimageGet or set focus area for crops to use
Can also be used as property: Pageimage::focus
 
Pageimage::page Page The Page object that this file is part of.  
Pageimage::pagefiles Pagefiles The Pagefiles WireArray that contains this file.  
Pageimage::sort int Sort order in database.  
Pageimage::suffix()
array boolReturns array of suffixes for this file, or true/false if this file has the given suffix.
Can also be used as property: Pageimage::suffix
 

Tags

NameReturnSummary 
Pageimage::tags string Value of the file’s tags field (string), if enabled.  
Pageimage::tagsArray array Get file tags as an array.  

Date time

NameReturnSummary 
Pageimage::created int Unix timestamp of when file was created.  
Pageimage::createdStr string Readable date/time string of when Pagefile was created  
Pageimage::modified int Unix timestamp of when Pagefile (file, description or tags) was last modified.  
Pageimage::modifiedStr string Readable date/time string of when Pagefile was last modified.  
Pageimage::mtime int Unix timestamp of when file (only) was last modified.  
Pageimage::mtimeStr string Readable date/time string when file (only) was last modified.  

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.135

Twitter updates

  • New post: Version 3.0.135 of ProcessWire on the dev branch focuses on some .htaccess updates, adds clarity to debug mode, and improves upon the installer— More
    5 July 2019
  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019
  • New post: This week we’ll take a look at 3 different WEBP image strategies that you can use in ProcessWire 3.0.132+. Then we’ll dive into a major update for the Google Client API module, and finish up by outlining some useful new updates in FormBuilder— More
    31 May 2019

Latest news

  • ProcessWire Weekly #270
    This week in the 270th issue of ProcessWire Weekly we're going to cover the SearchEngine module, feature some recent support forum highlights, and introduce a brand new site of the week. Read on!
    Weekly.pw / 13 July 2019
  • ProcessWire 3.0.135 core updates
    Version 3.0.135 of ProcessWire on the dev branch focuses on .htaccess updates, adds additional layers of security, adds clarity to debug mode, and improves upon the installer.
    Blog / 3 July 2019
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer