diff --git a/docs/changelog.md b/docs/changelog.md index 1364a70f..7a75bb77 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -21,6 +21,9 @@ Requires libvips v8.10.0 * Ensure `stats` can be calculated for 1x1 input. [#2372](https://github.com/lovell/sharp/issues/2372) +* Ensure animated GIF output is optimised. + [#2376](https://github.com/lovell/sharp/issues/2376) + ### v0.26.0 - 25th August 2020 * Prebuilt libvips binaries are now statically-linked and Brotli-compressed, requiring Node.js 10.16.0+. diff --git a/src/pipeline.cc b/src/pipeline.cc index 2163b55f..3081c336 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -782,6 +782,8 @@ class PipelineWorker : public Napi::AsyncWorker { sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF); VipsArea *area = VIPS_AREA(image.magicksave_buffer(VImage::option() ->set("strip", !baton->withMetadata) + ->set("optimize_gif_frames", TRUE) + ->set("optimize_gif_transparency", TRUE) ->set("format", "gif"))); baton->bufferOut = static_cast(area->data); baton->bufferOutLength = area->length; @@ -925,6 +927,8 @@ class PipelineWorker : public Napi::AsyncWorker { sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF); image.magicksave(const_cast(baton->fileOut.data()), VImage::option() ->set("strip", !baton->withMetadata) + ->set("optimize_gif_frames", TRUE) + ->set("optimize_gif_transparency", TRUE) ->set("format", "gif")); baton->formatOut = "gif"; } else if (baton->formatOut == "tiff" || (mightMatchInput && isTiff) ||