Skip to content

Format conversion

use SomehowDigital\ImgProxy\Url;
$base = Url::create()->source('https://example.com/photos/cat.jpg');

Pass the format to build(). It becomes the extension of the URL.

use SomehowDigital\ImgProxy\Option\Width;
$base->options(new Width(800))->build('webp');
// _/w:800/plain/https%3A%2F%2Fexample.com%2Fphotos%2Fcat.jpg@webp
use SomehowDigital\ImgProxy\Option\FormatQuality;
use SomehowDigital\ImgProxy\Option\Width;
$base->options(new Width(800), new FormatQuality(['webp' => 75, 'avif' => 60, 'jpeg' => 82]))->build();
// _/w:800/fq:webp:75:avif:60:jpeg:82/plain/https%3A%2F%2Fexample.com%2Fphotos%2Fcat.jpg

JPEG has no alpha channel, so fill the transparent areas.

use SomehowDigital\ImgProxy\Option\Background;
use SomehowDigital\ImgProxy\Option\Width;
$base->options(new Width(400), new Background('ffffff'))->build('jpg');
// _/w:400/bg:ffffff/plain/https%3A%2F%2Fexample.com%2Fphotos%2Fcat.jpg@jpg