Dynamic Images
The Dynamic Images API lets you resize, crop, and transform images in real time by appending query parameters to image URLs. No pre-processing or multiple file versions required, just add parameters to your image URLs and Bunny Optimizer handles the rest.
Usage
Generate URL with optimization parameters.
<?php
require 'vendor/autoload.php';
use ToshY\BunnyNet\BunnyDynamicImageProcessor;
BunnyDynamicImageProcessor::generate(
url: 'https://myzone.b-cdn.net/bunny.jpg',
optimization: [
'width' => 200,
'height' => 300,
'aspect_ratio' => '16:9',
'quality' => 85,
'sharpen' => false,
'blur' => 0,
'crop' => '50,50',
'crop_gravity' => 'center',
'flip' => false,
'flop' => false,
'brightness' => 0,
'saturation' => 0,
'hue' => 0,
'contrast' => 0,
'sepia' => 0,
'auto_optimize' => 'medium',
'class' => 'my-custom-class',
],
);
Note
- The
qualityargument determines the compression level of the resulting image with 0 being the lowest level of compression and 100 being the highest. Higher compression means smaller files, but might visually degrade the image (e.g. JPEG compression under 70 tends to produce visible artefacts). Thequalityargument is ignored if the requested output image format is lossless (e.g. PNG). - The
cropargument crops the output image to the given width and height. Two formats are accepted. Format 1 one only includes the width and height of the crop:width,height. Format 2 also includes the X and Y position of where the crop should start:width,height,x,y. Image resizing with the width and height parameters is processed after the crop and the resized measurements. If only width and height are given, theCrop Gravityparameter will be used.