sharp-heic-lambda-layer icon indicating copy to clipboard operation
sharp-heic-lambda-layer copied to clipboard

Can't save GIFs - gifsave_buffer not found

Open mikebarlow opened this issue 3 years ago • 7 comments

Hey, with the latest updates it appears that we can no longer save gif file types.

I'm getting the following error when I try to perform actions and save a gif image.

{ "errorType": "Error", "errorMessage": "VipsOperation: class \"gifsave_buffer\" not found\n", "trace": [ "Error: VipsOperation: class \"gifsave_buffer\" not found", "" ] }

I'm fairly sure this has occurred with the latest V3.0.0 release. I went back to an old version of the layer in AWS that was created using the 2.0.2release and GIFs are working again but HEIC/HEIF files are broken and don't save due to the version of SharpJS in use, so rolling back isn't an option.

This is our implementation of Sharp at the moment, I've simplified this somewhat however as we have a ton of different calculations in place for different file types and such

// srcFile is the Body buffer from S3 GetObject call
let image = sharp(srcFile, {animated: true});

image = await image.resize({
    width: newSize.width,
    height: newSize.height,
    fit: resizeType,
    background: {r: 255, g: 255, b: 255, alpha: 1},
});

processedBuffer = await image.toBuffer();

// processedBuffer is then passed to S3.putObject

Appreciate this may be SharpJS issue rather than an issue with the layer, however given this layer is the one loading in the packages for the different libs, I assumed it may be an issue here rather than Sharp itself.

mikebarlow avatar Sep 16 '22 10:09 mikebarlow

https://github.com/zoellner/sharp-heic-lambda-layer/pull/12 was meant to add GIF support @xtrinch can you comment on this?

zoellner avatar Sep 16 '22 15:09 zoellner

Gifs work for me, perhaps the usage differs. Here's mine:

    buffer = await Sharp(bodyContents, { animated: true })
        .rotate()
        .resize({
            width,
            height,
            fit: (format.fit || mode) as keyof FitEnum,
        }) // maximally double the largest dimension
        .toFormat("webp")
        .webp({
            quality: format.quality || 80,
        })
        .toBuffer();

This basically creates an animated webp out of a gif (I have not tried gif to gif however)

xtrinch avatar Sep 16 '22 15:09 xtrinch

Yeah, it seems the same aside from the output. We are wanting to keep the same file type at the moment so in our instance it is trying to save as a GIF.

I have tried both animated GIFs and a static GIF too with my code and I'm getting the same error. I have a fork of this repo and currently have a build running where I've bumped SharpJS to see if that fixes anything.

mikebarlow avatar Sep 16 '22 15:09 mikebarlow

Sadly that didn't work, still getting the same error when saving as gif. I have also tried bumping the libvips version at the top of the Makefile to, what appears to be their latest version, 8.13.1 and sadly still nothing.

mikebarlow avatar Sep 16 '22 16:09 mikebarlow

In that case I'd suggest to try your pipeline with the vanilla SharpJS version to check if it works there and if not open an issue with them.

zoellner avatar Sep 16 '22 16:09 zoellner

Yeah, looks like that will be my next step. @xtrinch are you able to confirm if your build works if you do change the output format to gif?

mikebarlow avatar Sep 19 '22 17:09 mikebarlow

Are you sure you're not installing sharp from npm separately? (i.e. double check that sharp is not in your package.json dependency). Gif output should work out of the box with prebuilt binaries too, and your error sounds like there's a mismatch in vips version for sharp (each sharp release needs a specific vips version)

xtrinch avatar Sep 19 '22 18:09 xtrinch