Image
Image
Image response class.
class Image extends \Hazaar\Controller\Response\FileResponseThis response specialisation wraps an image file object and exposes helper methods for common image operations such as format changes, resize/expand transformations, quality adjustments, and data-stream encoding.
It extends the file response pipeline so image data can still be returned with standard HTTP response handling while providing image-specific convenience methods for controllers.
Properties
file
The image file object backing this response.
protected ImageObject $fileMethods
__construct
Create a new image response.
public __construct(null $filename, ?int $quality, ?Manager $manager): voidInitializes the internal image object from a source file (or an empty image object when null is supplied), optionally setting output quality and a file manager context.
Parameters
| Parameter | Type | Description |
|---|---|---|
$filename | null | source image file object or path |
$quality | int | optional initial quality setting |
$manager | Manager | optional file manager for storage access |
load
Load an image into the response.
public load(string $file, ?Manager $manager): boolThe source is wrapped in an {@see ImageObject} and delegated to the parent file response loader.
Parameters
| Parameter | Type | Description |
|---|---|---|
$file | string | source file object or file path |
$manager | Manager | optional file manager for storage access |
setFormat
Set the output image format.
public setFormat(string $format): voidUpdates the image MIME content type using the provided format token.
Parameters
| Parameter | Type | Description |
|---|---|---|
$format | string | image format suffix (for example: png, jpeg, webp) |
width
Get the current image width.
public width(): ?intheight
Get the current image height.
public height(): ?intquality
Get or set image quality.
public quality(?int $quality): ?intWhen a value is provided, the underlying image quality is updated. The current quality value is always returned when available.
Parameters
| Parameter | Type | Description |
|---|---|---|
$quality | int | optional quality value to apply |
encodeDataStream
Encode the image content as a base64 data stream.
public encodeDataStream(): voidReplaces the response content with a data: URI containing the current image payload and switches the response content type to text/css for downstream CSS embedding scenarios.
getContent
Get the raw image content.
public getContent(): stringfileExists
Check whether the underlying image file exists.
public fileExists(): boolresize
Resize the image using the supplied transformation options.
public resize(?int $width, ?int $height, bool $crop, ?string $align, bool $keepAspect = true, bool $reduceOnly = true, ?float $ratio, int $offsetTop, int $offsetLeft): boolDelegates directly to the underlying image object and supports cropping, alignment, aspect-ratio preservation, reduction constraints, and offsets.
Parameters
| Parameter | Type | Description |
|---|---|---|
$width | int | target width in pixels |
$height | int | target height in pixels |
$crop | bool | whether to crop to fit dimensions |
$align | string | alignment strategy for crop/resize |
$keepAspect | bool | preserve source aspect ratio |
$reduceOnly | bool | prevent upsizing when true |
$ratio | float | optional explicit resize ratio |
$offsetTop | int | vertical offset |
$offsetLeft | int | horizontal offset |
expand
Expand the image canvas to the given dimensions.
public expand(?int $width, ?int $height, string $align = 'topleft', int $offsettop, int $offsetleft): boolDelegates to the image object expansion routine, allowing alignment and positional offsets for where the original image is placed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$width | int | target canvas width in pixels |
$height | int | target canvas height in pixels |
$align | string | alignment anchor used during expansion |
$offsettop | int | vertical offset for placement |
$offsetleft | int | horizontal offset for placement |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000