-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
advanced webp output options - alpha quality, lossless and near lossless #685
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, thanks for this, I'll added some comments inline.
@@ -145,6 +145,8 @@ const Sharp = function (input, options) { | |||
pngCompressionLevel: 6, | |||
pngAdaptiveFiltering: true, | |||
webpQuality: 80, | |||
webpAlphaQuality: 100, | |||
webpLossless: false, | |||
tiffQuality: 80, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this missing a webpNearLossless: false
default? This might be the reason for the "Partial image extraction WebP" test failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests on my system passed without this as well. Still added it.
@@ -168,6 +168,9 @@ const png = function png (options) { | |||
* Use these WebP options for output image. | |||
* @param {Object} [options] - output options | |||
* @param {Number} [options.quality=80] - quality, integer 1-100 | |||
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100 | |||
* @param {Boolean} [options.lossless=false] - use lossless compression mode | |||
* @param {Boolean} [options.nearLossless=false] - use near_lossless compression mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are lossless
and nearLossless
mutually exclusive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nearLossless
has to be used in conjunction with Q. nearLossless
with Q=100 is equivalent to lossless
. But with other quality settings, it will lead to a smaller file size than lossless
. This does make lossless
kind of redundant (https://groups.google.com/a/webmproject.org/forum/#!topic/webp-discuss/0GmxDmlexek) as a shorthand way of saying nearLossless, Q=100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my question wasn't very clear. What happens when trying to combine the two?
.webp({
lossless: true,
nearLossless: true
})...
Is this valid?
@@ -1209,6 +1218,11 @@ NAN_METHOD(pipeline) { | |||
baton->pngCompressionLevel = AttrTo<uint32_t>(options, "pngCompressionLevel"); | |||
baton->pngAdaptiveFiltering = AttrTo<bool>(options, "pngAdaptiveFiltering"); | |||
baton->webpQuality = AttrTo<uint32_t>(options, "webpQuality"); | |||
baton->webpAlphaQuality = AttrTo<uint32_t>(options, "webpAlphaQuality"); | |||
baton->webpLossless = AttrTo<bool>(options, "webpLossless"); | |||
if(HasAttr(options, "webpNearLossless")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this attribute need the HasAttr
check given there is (or should be) a default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the check since the default has been added
if (err) throw err; | ||
assert.strictEqual(true, data.length > 0); | ||
assert.strictEqual('webp', info.format); | ||
fixtures.assertSimilar(fixtures.expected('webp-alpha-80.webp'), data, function (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline function can be rolled up to use done
, something like:
fixtures.assertSimilar(fixtures.expected('webp-alpha-80.webp'), data, done);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out
@@ -735,6 +779,12 @@ describe('Input/output', function () { | |||
}); | |||
}); | |||
|
|||
it('Invalid WebP alpha quality throws error', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can you add tests for invalid lossless
and nearLossless
attributes also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid lossless
and nearLossless
attributes are ignored and are set to default boolean false
. Similar to what is done for jpegOvershootDeringing
and other such params
If it looks good now, I can squash it into a single commit? |
@@ -169,7 +169,7 @@ This operation will always occur after resizing and extraction, if any. | |||
// to the top, left and right edges and 20 to the bottom edge | |||
sharp(input) | |||
.resize(140) | |||
.background({r: 0, g: 0, b: 0, a: 0}) | |||
.background({r: 0, g: 0, b: 0, alpha: 0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was included in commit 4730554 so I think this file can be removed from the PR.
@@ -168,6 +168,9 @@ const png = function png (options) { | |||
* Use these WebP options for output image. | |||
* @param {Object} [options] - output options | |||
* @param {Number} [options.quality=80] - quality, integer 1-100 | |||
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100 | |||
* @param {Boolean} [options.lossless=false] - use lossless compression mode | |||
* @param {Boolean} [options.nearLossless=false] - use near_lossless compression mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my question wasn't very clear. What happens when trying to combine the two?
.webp({
lossless: true,
nearLossless: true
})...
Is this valid?
Since this is valid
should be considered valid. I will add a test for the same, that when both |
Fantastic, thank you very much for this Rahul. |
No description provided.