Skip to content

Commit 54d9dc4

Browse files
authoredMay 15, 2022
Fix rotate-then-extract for EXIF orientation 2 (#3218)
1 parent 51b4a7c commit 54d9dc4

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed
 

‎src/pipeline.cc

+10-8
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,18 @@ class PipelineWorker : public Napi::AsyncWorker {
9595
if (baton->rotateBeforePreExtract) {
9696
if (rotation != VIPS_ANGLE_D0) {
9797
image = image.rot(rotation);
98-
if (flip) {
99-
image = image.flip(VIPS_DIRECTION_VERTICAL);
100-
flip = FALSE;
101-
}
102-
if (flop) {
103-
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
104-
flop = FALSE;
105-
}
98+
}
99+
if (flip) {
100+
image = image.flip(VIPS_DIRECTION_VERTICAL);
101+
}
102+
if (flop) {
103+
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
104+
}
105+
if (rotation != VIPS_ANGLE_D0 || flip || flop) {
106106
image = sharp::RemoveExifOrientation(image);
107107
}
108+
flop = FALSE;
109+
flip = FALSE;
108110
if (baton->rotationAngle != 0.0) {
109111
MultiPageUnsupported(nPages, "Rotate");
110112
std::vector<double> background;

‎test/unit/extract.js

+44-7
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,51 @@ describe('Partial image extraction', function () {
168168
});
169169
});
170170

171-
it('Rotate with EXIF mirroring then extract', function (done) {
172-
sharp(fixtures.inputJpgWithLandscapeExif7)
173-
.rotate()
174-
.extract({ left: 0, top: 208, width: 60, height: 40 })
175-
.toBuffer(function (err, data) {
176-
if (err) throw err;
177-
fixtures.assertSimilar(fixtures.expected('rotate-mirror-extract.jpg'), data, done);
171+
describe('Apply exif orientation and mirroring then extract', () => {
172+
[
173+
{
174+
name: 'EXIF-1',
175+
image: fixtures.inputJpgWithLandscapeExif1
176+
},
177+
{
178+
name: 'EXIF-2',
179+
image: fixtures.inputJpgWithLandscapeExif2
180+
},
181+
{
182+
name: 'EXIF-3',
183+
image: fixtures.inputJpgWithLandscapeExif3
184+
},
185+
{
186+
name: 'EXIF-4',
187+
image: fixtures.inputJpgWithLandscapeExif4
188+
},
189+
{
190+
name: 'EXIF-5',
191+
image: fixtures.inputJpgWithLandscapeExif5
192+
},
193+
{
194+
name: 'EXIF-6',
195+
image: fixtures.inputJpgWithLandscapeExif6
196+
},
197+
{
198+
name: 'EXIF-7',
199+
image: fixtures.inputJpgWithLandscapeExif7
200+
},
201+
{
202+
name: 'EXIF-8',
203+
image: fixtures.inputJpgWithLandscapeExif8
204+
}
205+
].forEach(({ name, image }) => {
206+
it(name, function (done) {
207+
sharp(image)
208+
.rotate()
209+
.extract({ left: 0, top: 208, width: 60, height: 40 })
210+
.toBuffer(function (err, data) {
211+
if (err) throw err;
212+
fixtures.assertSimilar(fixtures.expected('rotate-mirror-extract.jpg'), data, done);
213+
});
178214
});
215+
});
179216
});
180217

181218
describe('Invalid parameters', function () {

0 commit comments

Comments
 (0)
Please sign in to comment.