__construct()
public function __construct(?string $filename = null)
Description
Constructor for the Image module. Blocks direct URL access and checks for the GD extension. If a filename is provided, loads the image for immediate processing.
Note: The framework automatically instantiates Image via $this->image. You rarely need to call this constructor manually.
Parameters
| Parameter | Type | Description | Default | Required |
|---|---|---|---|---|
| filename | string|null | Path to an image file to load immediately. If null, no image is loaded. | null | No |
Return Value
| Type | Description |
|---|---|
| void | Constructor does not return a value. |
Example Usage
PHP
<?php
// Automatic instantiation by framework (inside a controller)
class Products extends Trongate {
public function edit() {
// $this->image is automatically an Image instance
$this->image->resize(800, 600);
}
}
// Manual instantiation with pre-loading
$image = new Image('uploads/product.jpg');
$image->resize(300, 300);