-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite handling EXIF orientation — add tests, make it plugin-indepen…
…dent (#875) * Write tests for handling EXIF orientation * Slightly improve docs for a private function * Rewrite handling EXIF orientation Do not rely on .rotate() and .mirror() methods, which are defined in plugins. Instead, implement bitmap transformation functions, which then can be applied to move pixels around. This approach has two main benefits: no plugins are required, and everything happens in one pass.
- Loading branch information
Showing
2 changed files
with
141 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Jimp, getTestDir } from '@jimp/test-utils'; | ||
|
||
import configure from '@jimp/custom'; | ||
|
||
const jimp = configure({ plugins: [] }, Jimp); | ||
|
||
describe('EXIF orientation', () => { | ||
for (let orientation = 1; orientation <= 8; orientation++) { | ||
it(`is fixed when EXIF orientation is ${orientation}`, async () => { | ||
const regularImg = await imageWithOrientation(1); | ||
const orientedImg = await imageWithOrientation(orientation); | ||
|
||
orientedImg.getWidth().should.be.equal(regularImg.getWidth()); | ||
orientedImg.getHeight().should.be.equal(regularImg.getHeight()); | ||
Jimp.distance(regularImg, orientedImg).should.lessThan(0.07); | ||
}); | ||
} | ||
}); | ||
|
||
function imageWithOrientation(orientation) { | ||
const imageName = `Landscape_${orientation}.jpg`; | ||
const path = getTestDir(__dirname) + '/images/exif-orientation/' + imageName; | ||
return jimp.read(path); | ||
} |