-
-
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
Add support for vips_rotate. #1385
Conversation
d9ba5cf
to
6b49d7d
Compare
Thank you - I should have some time tomorrow to take a proper look at this. |
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 again for this, I've made a few comments inline. It looks like you'll need to rebase against upstream/teeth
then run npm run docs
to remove the extraneous changes that have crept into docs/api-operation.md
.
lib/operation.js
Outdated
} else { | ||
throw new Error('Unsupported angle: angle must be a positive/negative multiple of 90 ' + angle); | ||
throw new Error('Unsupported angle: angle must be a positive or negative number.'); |
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.
Can this now be reduced to angle must be a number
?
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.
Yup!
@@ -108,6 +108,8 @@ const Sharp = function (input, options) { | |||
embed: 0, | |||
useExifOrientation: false, | |||
angle: 0, | |||
rotationAngle: 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.
I'm not sure if it was intentional but using a separate parameter here has the advantage of allowing both EXIF auto-rotation and a custom angle rotation in the same pipeline.
sharp(input)
.rotate() // auto-rotate based on EXIF, then
.rotate(42) // rotate to specific angle
...
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.
Actually no, that wasn't intentional :)
But sounds good to me. Keep it?
@@ -45,6 +83,17 @@ describe('Rotation', function () { | |||
}); | |||
}); | |||
|
|||
[-3750, -510, -150, 30, 390, 3630].forEach(function (angle) { |
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 is a great test scenario, thank you.
lib/operation.js
Outdated
if (!is.defined(angle)) { | ||
this.options.useExifOrientation = true; | ||
} else if (is.integer(angle) && !(angle % 90)) { | ||
this.options.angle = angle; | ||
} else if (is.number(angle)) { | ||
this.options.rotationAngle = angle; | ||
if (options && options.background) { |
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.
There's an is.object
check available that could be used here.
lib/operation.js
Outdated
* For example, `-450` will produce a 270deg rotation. | ||
* | ||
* If a non-rectangular angle is provided, the color of the background color |
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.
I think the mathematical term would be "non-quadrantal angle" but maybe "angles that are not multiple of 90" would be better understood.
Thanks for the review, pushed an update with your suggestions. |
Marvellous, thank you very much, this will be included in sharp v0.21.0. |
Wonderful, cheers! |
When is |
@benoj You can track the progress of everything planned for inclusion in v0.21.0 at https://github.com/lovell/sharp/milestone/40 |
This PR adds support for arbitrary rotation angles.
Instead of only being able to rotate multiples of 90 degrees, any angle can now be applied, using libvips'
vips_rotate
API, introduced in the recently released v8.7.0.The JavaScript API stays the same, however a new optional
background
parameter can be provided to set the background color of the rotated image.The new code is covered in tests, let me know if that's enough or more test cases are needed. For the documentation I'm not sure why it seems to have generated additional documentation for
extend
,extract
andtrim
, maybe those weren't generated before?This PR closes #998.