Skip to content

Commit

Permalink
Add the &ll parameter (#386)
Browse files Browse the repository at this point in the history
To control whether the resulting image should be lossless compressed.

This only applies to formats that offer both lossy and lossless
compression capabilities, such as WebP.
  • Loading branch information
kleisauke committed Sep 1, 2023
1 parent e5489aa commit 0674c39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/api/parsers/query.cpp
Expand Up @@ -14,8 +14,8 @@ using enums::MaskType;
using enums::Output;
using enums::Position;

// `&[precrop]=true`
constexpr size_t MAX_KEY_LENGTH = sizeof("precrop") - 1;
// `&[lossless]=true`
constexpr size_t MAX_KEY_LENGTH = sizeof("lossless") - 1;

// A vector must not have more than 65536 elements.
const size_t MAX_VECTOR_SIZE = 65536;
Expand Down Expand Up @@ -66,6 +66,7 @@ const TypeMap &type_map = {
{"l", typeid(int)},
{"output", typeid(Output)},
{"il", typeid(bool)},
{"ll", typeid(bool)}, // TODO(kleisauke): Documentation needed.
{"af", typeid(bool)},
{"page", typeid(int)},
{"n", typeid(int)},
Expand All @@ -75,19 +76,20 @@ const TypeMap &type_map = {
};

const SynonymMap &synonym_map = {
{"shape", "mask"}, // &shape= was deprecated since API version 4
{"strim", "mtrim"}, // &strim= was deprecated since API version 4
{"or", "ro"}, // &or= was deprecated since API version 5
{"t", "fit"}, // &t= was deprecated since API version 5
{"shape", "mask"}, // &shape= was deprecated since API version 4
{"strim", "mtrim"}, // &strim= was deprecated since API version 4
{"or", "ro"}, // &or= was deprecated since API version 5
{"t", "fit"}, // &t= was deprecated since API version 5
// TODO(kleisauke): Synonym this within a major release (since it breaks BC).
//{"bri", "mod"},
//{"bri", "mod"},
// Some handy synonyms
{"pages", "n"},
{"width", "w"},
{"height", "h"},
{"align", "a"},
{"level", "l"},
{"quality", "q"},
{"pages", "n"},
{"width", "w"},
{"height", "h"},
{"align", "a"},
{"level", "l"},
{"quality", "q"},
{"lossless", "ll"},
};

const NginxKeySet &nginx_keys = {
Expand Down
3 changes: 3 additions & 0 deletions src/api/processors/stream.cpp
Expand Up @@ -356,6 +356,9 @@ void Stream::append_save_options<Output::Webp>(vips::VOption *options) const {
},
static_cast<int>(config_.webp_quality));

// Enable lossless compression, if necessary
options->set("lossless", query_->get<bool>("ll", false));

// Set quality (default is 80)
options->set("Q", quality);

Expand Down

0 comments on commit 0674c39

Please sign in to comment.