From 1e4597c284f3d572f4cd21d5bbb3fc0523f77ce9 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 10 Mar 2019 17:26:26 +0000 Subject: [PATCH] Changelog entry for #1595 (plus add GIF) --- docs/changelog.md | 4 ++++ lib/input.js | 2 +- src/common.cc | 14 ++++++++++++-- src/common.h | 5 +++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index cc372ca2..676f0bb4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -12,6 +12,10 @@ Requires libvips v8.7.4. * Add `composite` operation supporting multiple images and blend modes; deprecate `overlayWith`. [#728](https://github.com/lovell/sharp/issues/728) +* Add support for `page` input option to GIF and PDF. + [#1595](https://github.com/lovell/sharp/pull/1595) + [@ramiel](https://github.com/ramiel) + ### v0.21 - "*teeth*" Requires libvips v8.7.0. diff --git a/lib/input.js b/lib/input.js index 10155e0f..3779c0f5 100644 --- a/lib/input.js +++ b/lib/input.js @@ -57,7 +57,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) { throw new Error('Expected width, height and channels for raw pixel input'); } } - // Page input for multi-page TIFF + // Page input for multi-page images (GIF, TIFF, PDF) if (is.defined(inputOptions.page)) { if (is.integer(inputOptions.page) && is.inRange(inputOptions.page, 0, 100000)) { inputDescriptor.page = inputOptions.page; diff --git a/src/common.cc b/src/common.cc index 6d3f870c..6e9b091e 100644 --- a/src/common.cc +++ b/src/common.cc @@ -212,6 +212,16 @@ namespace sharp { return imageType; } + /* + Does this image type support multiple pages? + */ + bool ImageTypeSupportsPage(ImageType imageType) { + return + imageType == ImageType::GIF || + imageType == ImageType::TIFF || + imageType == ImageType::PDF; + } + /* Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data) */ @@ -243,7 +253,7 @@ namespace sharp { if (imageType == ImageType::MAGICK) { option->set("density", std::to_string(descriptor->density).data()); } - if (imageType == ImageType::TIFF || imageType == ImageType::PDF) { + if (ImageTypeSupportsPage(imageType)) { option->set("page", descriptor->page); } image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option); @@ -288,7 +298,7 @@ namespace sharp { if (imageType == ImageType::MAGICK) { option->set("density", std::to_string(descriptor->density).data()); } - if (imageType == ImageType::TIFF || imageType == ImageType::PDF) { + if (ImageTypeSupportsPage(imageType)) { option->set("page", descriptor->page); } image = VImage::new_from_file(descriptor->file.data(), option); diff --git a/src/common.h b/src/common.h index 210558d3..4da7f361 100644 --- a/src/common.h +++ b/src/common.h @@ -140,6 +140,11 @@ namespace sharp { */ ImageType DetermineImageType(char const *file); + /* + Does this image type support multiple pages? + */ + bool ImageTypeSupportsPage(ImageType imageType); + /* Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data) */