Add support for arbitrary rotation angle via vips_rotate (#1385)

This commit is contained in:
freezy
2018-09-27 19:00:36 +02:00
committed by Lovell Fuller
parent 37d385fafa
commit 796738da65
8 changed files with 163 additions and 36 deletions

View File

@@ -476,6 +476,13 @@ class PipelineWorker : public Nan::AsyncWorker {
}
}
// Rotate by degree
if (baton->rotationAngle != 0.0) {
std::vector<double> background;
std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground);
image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background));
}
// Post extraction
if (baton->topOffsetPost != -1) {
image = image.extract_area(
@@ -1187,6 +1194,12 @@ NAN_METHOD(pipeline) {
baton->normalise = AttrTo<bool>(options, "normalise");
baton->useExifOrientation = AttrTo<bool>(options, "useExifOrientation");
baton->angle = AttrTo<int32_t>(options, "angle");
baton->rotationAngle = AttrTo<double>(options, "rotationAngle");
// Rotation background colour
v8::Local<v8::Object> rotationBackground = AttrAs<v8::Object>(options, "rotationBackground");
for (unsigned int i = 0; i < 4; i++) {
baton->rotationBackground[i] = AttrTo<double>(rotationBackground, i);
}
baton->rotateBeforePreExtract = AttrTo<bool>(options, "rotateBeforePreExtract");
baton->flip = AttrTo<bool>(options, "flip");
baton->flop = AttrTo<bool>(options, "flop");

View File

@@ -89,6 +89,8 @@ struct PipelineBaton {
bool normalise;
bool useExifOrientation;
int angle;
double rotationAngle;
double rotationBackground[4];
bool rotateBeforePreExtract;
bool flip;
bool flop;
@@ -180,6 +182,7 @@ struct PipelineBaton {
normalise(false),
useExifOrientation(false),
angle(0),
rotationAngle(0.0),
flip(false),
flop(false),
extendTop(0),