Encoding
Encoding
format(Format $format)
Set the output format.
use Timber\Chainsaw\Enum\Format;
$image->format(Format::Webp);
$image->format(Format::Avif);
$image->format(Format::Png);
$image->format(Format::Jpg);
$image->format(Format::Gif);
Auto format
Format::Auto defers the concrete format to URL-build time. CDN providers that support it (Cloudflare, Cloudinary, ImageKit, imgix) negotiate at the edge. The local providers (InterventionProvider, ImagineProvider) delegate to an AutoFormatStrategyInterface that you inject — the library ships no Accept-header parser of its own, so without a strategy Format::Auto throws:
$image->format(Format::Auto); // resolved by the strategy you inject
See Advanced > Format negotiation for a copy-paste strategy and the full-page-cache caveat.
quality(int $quality)
Set JPEG/WebP/AVIF quality. Range: 0–100.
$image->quality(80);
Presets
Apply a named preset registered on the factory:
use Timber\Chainsaw\ImageFactory;
use Timber\Chainsaw\Manipulator\Crop;
use Timber\Chainsaw\Preset;
use Timber\Chainsaw\Presets;
// Registration
$factory = new ImageFactory(
provider: $provider,
presets: (new Presets())->add(new Preset('thumbnail', [new Crop(200, 200)])),
);
// Usage
$image->preset('thumbnail');
Presets can include encoding:
$presets = (new Presets())
->add(new Preset(
'hero-webp',
[new Crop(1200, 600)],
new Encoding(format: Format::Webp, quality: 85),
));
$factory = new ImageFactory(provider: $provider, presets: $presets);