Skip to content

Converters

Jan Hermann edited this page Oct 9, 2026 · 1 revision

🔄

Conversion of images to WebP and AVIF.

Thumbnails are converted automatically when formats is set in the configuration. The converters can be used on their own too.

Enum of supported formats: Format::WEBP (webp) and Format::AVIF (avif).

fromConfig

Format::fromConfig(string|int|self $value): self creates a format from webp, Webp, a class constant like Image::WEBP or IMAGETYPE_WEBP / IMAGETYPE_AVIF. Throws \InvalidArgumentException for an unsupported format.

Abstract class for converters. The converted file is saved next to the original with the extension appended (image.jpg → image.jpg.webp).

convert

convert(string $path, bool $replace = false): bool converts one file. Returns true when the file was converted, false when it does not exist, is already in the format, the converted file exists already (and $replace is false) or the image can not be read.

Throws UnsupportedFormatException or NoDriverException if PHP can not write the format at all.

convertFolder

convertFolder(string $path, bool $replace = false, array $masks = ["*"]): void converts all files in the folder (including subfolders) whose names match the masks.

save

save(string $filename) writes the converted file with the driver which supports the format (ImagineFactory).

Classes that extend Converter for WebP and AVIF.

use Imagony\Converters\{AvifConverter, WebpConverter};

(new WebpConverter())->convert("/var/www/public/images/photo.jpg");
(new AvifConverter())->convertFolder("/var/www/public/images", false, ["*.jpg", "*.png"]);

Clone this wiki locally