Skip to content

Unable to Write AVIF to Buffer Using .avif Suffix #197

Closed
@freshleafmedia

Description

@freshleafmedia

If I try to re-encode an image from JPEG to AVIF everything works as expected:

$image = \Jcupitt\Vips\Image::newFromFile('path/to/image.jpg');
$image->writeToFile('path/to/image.avif');

However if I try to write the AVIF image to a buffer I get an error:

$image = \Jcupitt\Vips\Image::newFromFile('path/to/image.jpg');
$buffer = $image->writeToBuffer('.avif');
libvips error: VipsForeignSave: ".avif" is not a known buffer format

The difference seems to be in the vips_foreign_find methods:

FFI::vips()->vips_foreign_find_save('.avif'); // "VipsForeignSaveHeifFile"
FFI::vips()->vips_foreign_find_save_buffer('.avif'); // null

I can get it to do it if I use the following workaround:

$image = \Jcupitt\Vips\Image::newFromFile('path/to/image.jpg');
$buffer = $image->writeToBuffer('.heif', ['compression' => 'av1'])

Am I doing something wrong or is this expected behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions