Image
Image
File wrapper with image-specific rendering and transformation helpers.
class Image extends \Hazaar\File\FileThe class delegates image operations to a renderer implementation (Imagick or GD) while preserving the standard Hazaar\File interface.
Properties
renderer
Active image renderer used for loading and transforming image bytes.
private BaseRenderer $rendererMethods
__construct
Creates an image file wrapper and selects the rendering backend.
public __construct(?string $filename, ?int $quality, ?Manager $manager, string $renderer = 'default'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$filename | string | file path/name |
$quality | int | optional output quality hint |
$manager | Manager | optional file manager backend |
$renderer | string | renderer preference (default, imagick, gd) |
setContents
Loads raw image bytes into the renderer and updates in-memory state.
public setContents(?string $bytes): intParameters
| Parameter | Type | Description |
|---|---|---|
$bytes | string | raw image data |
getContents
Returns current image bytes from the renderer.
public getContents(int $offset = -1, ?int $maxlen): stringThe renderer is lazily loaded from parent file contents if needed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | optional byte offset for initial parent read |
$maxlen | int | optional maximum bytes for initial parent read |
thumbnail
Convenience helper that resizes the image to a 100x100 thumbnail.
public thumbnail(): boolquality
Gets or sets renderer output quality.
public quality(?int $quality): intParameters
| Parameter | Type | Description |
|---|---|---|
$quality | int | when provided, updates quality before returning it |
width
Returns current image width in pixels.
public width(): intheight
Returns current image height in pixels.
public height(): inthasContents
Returns whether the image currently has loaded pixel content.
public hasContents(): boolresize
Resizes the image with optional cropping/aspect and offset controls.
public resize(?int $width, ?int $height, bool $crop, ?string $align, bool $keepAspect = true, bool $reduceOnly = true, ?float $ratio, int $offsetTop, int $offsetLeft): boolParameters
| Parameter | Type | Description |
|---|---|---|
$width | int | target width |
$height | int | target height |
$crop | bool | whether to crop to exact dimensions |
$align | string | crop/placement alignment hint |
$keepAspect | bool | whether aspect ratio should be preserved |
$reduceOnly | bool | prevent upscaling when true |
$ratio | float | explicit ratio override |
$offsetTop | int | vertical offset |
$offsetLeft | int | horizontal offset |
expand
Expands canvas dimensions and positions image using alignment rules.
public expand(?int $xwidth, ?int $xheight, string $align = 'topleft', int $offsetTop, int $offsetLeft): boolParameters
| Parameter | Type | Description |
|---|---|---|
$xwidth | int | extra width |
$xheight | int | extra height |
$align | string | placement alignment |
$offsetTop | int | vertical offset |
$offsetLeft | int | horizontal offset |
getResponseObject
Returns a HTTP image response wrapper for this image file.
public getResponseObject(): ResponsegetRenderer
Resolves and instantiates the preferred renderer implementation.
private getRenderer(string $renderer, ?int $quality): BaseRendererFalls back to GD when Imagick is unavailable.
Parameters
| Parameter | Type | Description |
|---|---|---|
$renderer | string | requested renderer name |
$quality | int | optional output quality hint |
checkLoaded
Ensures renderer has image data loaded before operations run.
private checkLoaded(): voidGenerated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000