Image
Image
File wrapper with image-specific rendering and transformation helpers.
class Image extends \Hazaar\FileExtends: Hazaar\File
The 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 $rendererType: Hazaar\File\Renderer\BaseRenderer
Methods
__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 | Hazaar\File\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): intReturns: int
Parameters
| Parameter | Type | Description |
|---|---|---|
$bytes | string | raw image data |
getContents
Returns current image bytes from the renderer.
public getContents(int $offset = -1, ?int $maxlen): stringReturns: string
The 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(): boolReturns: bool
quality
Gets or sets renderer output quality.
public quality(?int $quality): intReturns: int
Parameters
| Parameter | Type | Description |
|---|---|---|
$quality | int | when provided, updates quality before returning it |
width
Returns current image width in pixels.
public width(): intReturns: int
height
Returns current image height in pixels.
public height(): intReturns: int
hasContents
Returns whether the image currently has loaded pixel content.
public hasContents(): boolReturns: bool
resize
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): boolReturns: bool
Parameters
| 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): boolReturns: bool
Parameters
| 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(): ResponseReturns: Hazaar\Controller\Response
getRenderer
Resolves and instantiates the preferred renderer implementation.
private getRenderer(string $renderer, ?int $quality): BaseRendererReturns: Hazaar\File\Renderer\BaseRenderer
Falls 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(): voidReturns: void
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000