objects

PageImage

A PageFile that is an image. transform() (and the src()/srcset() helpers built on it) only compute the target variant URL and record the requested options via Registry::setVariant() : no pixels are touched here.

The variant is rendered on first request, when Page::route() dispatches to PageFiles::variant(), which is the only place that actually decodes and re-encodes image bytes.

$pageImage Phlat\Files\PageImage extends PageFile 22 methods
Properties (14)
$pageImage->pageUuid string readonly
$pageImage->filename string readonly
$pageImage->fields array readonly Custom metadata values, keyed by field name - declared under files/{type}/_index.json's own "fields" key ($this->type: image, video, audio, document, ...), resolved lazily via field()/fieldSet().
$pageImage->uri string readonly
$pageImage->name ?string readonly
$pageImage->directory ?string readonly
$pageImage->basename ?string readonly
$pageImage->extension ?string readonly
$pageImage->modified ?int readonly
$pageImage->size ?int readonly
$pageImage->contents ?string
$pageImage->mime ?string
$pageImage->type ?string
$pageImage->path string readonly
Show
  • base64 Encodes the requested variant as a data: URI, generating it straight into its real public path (the same lookup Page::route() uses to dispatch a live request for it) if it isn't already there - no separate temp file.
  • color The most common color as #rrggbb.
  • draw A variant URL with one layer drawn over it: `drawLayers([$layer], $options)`.
  • drawLayers A variant URL with $layers drawn over it, in order, after $options (the usual `w=,h=,…`) are applied.
  • height Height in pixels, or null when unreadable.
  • isLandscape Whether it is wider than tall.
  • isPortrait Whether it is taller than wide.
  • isSquare Whether width and height are equal.
  • palette The $count most common colors as #rrggbb, most common first.
  • placeholder A data: URI for a plain $w by $h SVG, to hold an image's space.
  • ratio Width divided by height, or null when unreadable.
  • src The URL of a variant: `$image->src('w=800')`.
  • srcset A srcset value from presets or option strings: `['w=400', 'w=800']` or `['w=800' => '2x']`.
  • transform The URL of a variant made with $options (`w=400,h=300,fit=cover`) or a preset name; null when no variant can be made.
  • variantPath The variant's file on disk, generated first when it isn't there yet.
  • width Width in pixels, or null when unreadable.

From PageFile 4

  • field A custom metadata field declared in files/{type}/_index.json's own "fields" list, resolved against this file's stored value.
  • fieldSet All declared custom metadata fields as resolved FieldValue instances.
  • isPublic True when a template has exposed this file, or any variant of it - see PageFiles::setVariant().
  • url The public URL, with a cache-busting suffix unless $cache_bust is false; null for a file with no owner.

Methods

$pageImage->base64(string $options = ''): string

Encodes the requested variant as a data: URI, generating it straight into its real public path (the same lookup Page::route() uses to dispatch a live request for it) if it isn't already there - no separate temp file.

Parameters (1)
$options string = ''

Returns string

phlat/src/Files/PageImage.php:144
$pageImage->color(): string

The most common color as #rrggbb.

Returns string

phlat/src/Files/PageImage.php:65
$pageImage->draw(string $layer, string $options = ''): string

A variant URL with one layer drawn over it: `drawLayers([$layer], $options)`.

Parameters (2)
$layer string
$options string = ''

Returns string

phlat/src/Files/PageImage.php:111
$pageImage->drawLayers(array $layers, string $options = ''): string

A variant URL with $layers drawn over it, in order, after $options (the usual `w=,h=,…`) are applied.

A layer is a string (rect,y=-80,h=80,bg=#000a), the name of a drawing in images.drawings, or an array merged into the layer before it for values that shouldn't be escaped into a string: ['caption', ['text' => $page->title]].

Parameters (2)
$layers array
$options string = ''

Returns string

phlat/src/Files/PageImage.php:93
$pageImage->height(): ?int

Height in pixels, or null when unreadable.

Returns ?int

phlat/src/Files/PageImage.php:41
$pageImage->isLandscape(): bool

Whether it is wider than tall.

Returns bool

phlat/src/Files/PageImage.php:71
$pageImage->isPortrait(): bool

Whether it is taller than wide.

Returns bool

phlat/src/Files/PageImage.php:73
$pageImage->isSquare(): bool

Whether width and height are equal.

Returns bool

phlat/src/Files/PageImage.php:75
$pageImage->palette(int $count = 5): list<string>

The $count most common colors as #rrggbb, most common first.

Parameters (1)
$count int = 5

Returns list<string>

phlat/src/Files/PageImage.php:59

placeholder

static
PageImage::placeholder(int $w, int $h, string $color = 'transparent'): string

A data: URI for a plain $w by $h SVG, to hold an image's space.

Parameters (3)
$w int
$h int
$color string = 'transparent'

Returns string

phlat/src/Files/PageImage.php:155
$pageImage->ratio(): ?float

Width divided by height, or null when unreadable.

Returns ?float

phlat/src/Files/PageImage.php:47

src

$pageImage->src(string $options = ''): string

The URL of a variant: `$image->src('w=800')`.

An empty string when none can be made.

Parameters (1)
$options string = ''

Returns string

phlat/src/Files/PageImage.php:83
$pageImage->srcset(array $variants): string

A srcset value from presets or option strings: `['w=400', 'w=800']` or `['w=800' => '2x']`.

Parameters (1)
$variants array

Returns string

phlat/src/Files/PageImage.php:117
$pageImage->transform(string $options = ''): ?string

The URL of a variant made with $options (`w=400,h=300,fit=cover`) or a preset name; null when no variant can be made.

Parameters (1)
$options string = ''

Returns ?string

phlat/src/Files/PageImage.php:43
$pageImage->variantPath(string $options = ''): string

The variant's file on disk, generated first when it isn't there yet.

Empty when the file has no variant.

Parameters (1)
$options string = ''

Returns string

phlat/src/Files/PageImage.php:22
$pageImage->width(): ?int

Width in pixels, or null when unreadable.

Returns ?int

phlat/src/Files/PageImage.php:35

From File

dir

$pageImage->dir(): string

Returns string

phlat/src/Files/File.php:66
$pageImage->exists(): bool

Returns bool

phlat/src/Files/File.php:71

From PageFile

$pageImage->field(string $key): FieldValue

A custom metadata field declared in files/{type}/_index.json's own "fields" list, resolved against this file's stored value.

Parameters (1)
$key string

Returns FieldValue

phlat/src/Files/PageFile.php:32
$pageImage->fieldSet(): FieldValueSet

All declared custom metadata fields as resolved FieldValue instances.

Returns FieldValueSet

phlat/src/Files/PageFile.php:38
$pageImage->isPublic(): bool

True when a template has exposed this file, or any variant of it - see PageFiles::setVariant().

Returns bool

phlat/src/Files/PageFile.php:60

url

$pageImage->url(bool $cache_bust = true): ?string

The public URL, with a cache-busting suffix unless $cache_bust is false; null for a file with no owner.

Parameters (1)
$cache_bust bool = true

Returns ?string

phlat/src/Files/PageFile.php:44