Skip to content

[13.x] Add PNG, GIF, AVIF, and BMP output formats to the Image component#60713

Draft
Tresor-Kasenda wants to merge 2 commits into
laravel:13.xfrom
Tresor-Kasenda:feat/image-additional-output-formats
Draft

[13.x] Add PNG, GIF, AVIF, and BMP output formats to the Image component#60713
Tresor-Kasenda wants to merge 2 commits into
laravel:13.xfrom
Tresor-Kasenda:feat/image-additional-output-formats

Conversation

@Tresor-Kasenda

Copy link
Copy Markdown
Contributor

Summary

Illuminate\Image\Image::toFormat() currently only supports converting to webp, jpg, and jpeg, even though the underlying Intervention Image encoders for png, gif, avif, and bmp are already bundled and used elsewhere in the driver (MediaTypeEncoder fallback). This adds first-class fluent methods for the missing formats, following the exact same pattern as the existing ones.

  • Image::toPng()
  • Image::toGif()
  • Image::toAvif()
  • Image::toBmp()
use Illuminate\Support\Facades\Image;

// Before: only webp/jpg/jpeg were reachable through toFormat()
Image::fromUpload($request->file('avatar'))
    ->cover(400, 400)
    ->toWebp()
    ->store('avatars');

// Now also possible:
Image::fromUpload($request->file('avatar'))
    ->cover(400, 400)
    ->toAvif()
    ->quality(80)
    ->store('avatars'); // stored with the correct .avif extension

Image::fromPath(storage_path('app/logo.png'))
    ->toGif()
    ->toBase64();

Image::fromUpload($request->file('scan'))
    ->toBmp()
    ->toDataUri();

Also fixes Image::extension(), which was missing the image/avif MIME type mapping and would have produced a .bin extension for AVIF outputs stored via store()/storeAs().

The `Image` component only supported converting to webp/jpg/jpeg via
`toFormat()`, even though the underlying Intervention Image encoders
for png, gif, avif, and bmp were already available. Adds `toPng()`,
`toGif()`, `toAvif()`, and `toBmp()` following the same pattern as the
existing format methods.
CI failed because getimagesizefromstring() and finfo's AVIF detection
depend on the libavif/libmagic versions installed on the runner, which
differ from the local dev environment. The driver test now inspects
the raw ISOBMFF ftyp box/brand instead of relying on
getimagesizefromstring(), and the extension() regression test skips
itself when the local fileinfo database doesn't recognize AVIF.
@taylorotwell

Copy link
Copy Markdown
Member

Tests are failing.

@taylorotwell taylorotwell marked this pull request as draft July 9, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants