1. Go to this page and download the library: Download brammo/image library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
brammo / image example snippets
public function bootstrap(): void
{
parent::bootstrap();
$this->addPlugin('Brammo/Image');
}
public function initialize(): void
{
parent::initialize();
// Load individual helpers
$this->loadHelper('Brammo/Image.Image');
}
// In AppView.php
$this->loadHelper('Brammo/Image.Image');
// With custom configuration
$this->loadHelper('Brammo/Image.Image', [
'tempFolder' => '/cache/images', // Cache folder (relative to webroot)
'driver' => 'auto', // 'auto', 'imagick', 'vips', or 'gd'
'backgroundColor' => '#ffffff', // Background color for fit method
]);
// Resize to fit within 200x200 (maintains aspect ratio)
echo $this->Image->resize('/images/photo.jpg', 200, 200);
// Returns: /thumb/200x200/images/photo.jpg
// Square shorthand (height = width)
echo $this->Image->resize('/images/photo.jpg', 200);
// Convert to WebP format
echo $this->Image->resize('/images/photo.jpg', 200, 200, 'webp');
// Returns: /thumb/200x200/images/photo.webp
// Fit within 300x200, pad with white background
echo $this->Image->fit('/images/photo.jpg', 300, 200);
// Returns: /thumb/300x200f/images/photo.jpg
// Custom background color (configured in helper options)
$this->loadHelper('Brammo/Image.Image', [
'backgroundColor' => '#000000', // Black background
]);