Skip to content
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

Maintant orientation specified in EXIF data #132

Merged
merged 4 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions img.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ class Image {
let results = [];
let outputFormats = Image.getFormatsArray(this.options.formats);

// Orientation 5 to 8 means dimensions are fliped
if (metadata.orientation >= 5) {
let height = metadata.height;
let width = metadata.width;
metadata.width = height;
metadata.height = width;
}

for(let outputFormat of outputFormats) {
if(!outputFormat || outputFormat === "auto") {
outputFormat = metadata.format || this.options.overrideInputFormat;
Expand Down Expand Up @@ -434,7 +442,10 @@ class Image {
if(metadata.format !== "svg" || !this.options.svgAllowUpscale) {
resizeOptions.withoutEnlargement = true;
}
sharpInstance.rotate();
sharpInstance.resize(resizeOptions);
} else if (stat.width === metadata.width && metadata.format !== "svg") {
sharpInstance.rotate();
}

if(!this.options.dryRun) {
Expand Down
Binary file added test/orientation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ test("Use exact same width as original", async t => {
t.is(stats.jpeg[0].width, 1280);
});

test("Maintains orientation", async t => {
let stats = await eleventyImage("./test/orientation.jpg", {
widths: [151],
formats: ["jpeg"],
outputDir: "./test/img/"
});

t.is(stats.jpeg.length, 1);
t.is(stats.jpeg[0].width, 76);
t.is(stats.jpeg[0].height, 151);
});

test("Try to use a width larger than original (statsSync)", t => {
let stats = eleventyImage.statsSync("./test/bio-2017.jpg", {
widths: [1500],
Expand Down