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

fix: Handle EXIF orientation in uploaded gallery images (#1617, #1694). #2039

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion app/back-end/helpers/avatar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const sizeOf = require('image-size');
const sizeOf = require('./rotation-aware-sizeof.js');

class AvatarHelper {
/*
Expand Down
30 changes: 30 additions & 0 deletions app/back-end/helpers/rotation-aware-sizeof.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Rotation-aware sizeOf().
*
* Images can contain an embedded orientation field, which indicates that they
* should be rotated before display. sizeOf() from image-size provides the original
* width and height, and the EXIF orientation value.
*
* For example, a 3000x4000 portrait image shot on an iPhone and exported from Apple
* Photos will appear to have width=4000, height=3000, orientation=6.
*
* We often need the rotated dimension ([3000, 4000] for the above example image),
* most notably when initializing a Photoswipe gallery, so this module provides a
* sizeOf() that returns [width, height] after rotation,
* i.e. [3000, 4000] for the above example image.
*/

const originalSizeOf = require('image-size');

function sizeOf(image) {
const info = originalSizeOf(image);
if (info.orientation == 6 || info.orientation == 8) {
return {
width: info.height,
height: info.width
};
}
return info;
}

module.exports = sizeOf;
2 changes: 1 addition & 1 deletion app/back-end/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const fs = require('fs-extra');
const path = require('path');
const Model = require('./model.js');
const sizeOf = require('image-size');
const sizeOf = require('./helpers/rotation-aware-sizeof.js');
const normalizePath = require('normalize-path');
const Themes = require('./themes.js');
const Utils = require('./helpers/utils.js');
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/modules/render-html/contexts/page-preview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Necessary packages
const fs = require('fs');
const path = require('path');
const sizeOf = require('image-size');
const sizeOf = require('./../../../helpers/rotation-aware-sizeof.js');
const sqlString = require('sqlstring');
const normalizePath = require('normalize-path');
const slug = require('./../../../helpers/slug');
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/modules/render-html/contexts/post-preview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Necessary packages
const fs = require('fs');
const path = require('path');
const sizeOf = require('image-size');
const sizeOf = require('./../../../helpers/rotation-aware-sizeof.js');
const sqlString = require('sqlstring');
const normalizePath = require('normalize-path');
const slug = require('./../../../helpers/slug');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Handlebars = require('handlebars');
const sizeOf = require('image-size');
const sizeOf = require('./../../../../helpers/rotation-aware-sizeof.js');
const path = require('path');
const normalizePath = require('normalize-path');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Handlebars = require('handlebars');
const moment = require('moment');
const sizeOf = require('image-size');
const sizeOf = require('./../../../../helpers/rotation-aware-sizeof.js');
const path = require('path');
const URLHelper = require('../../helpers/url');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const stripTags = require('striptags');
const sizeOf = require('image-size');
const sizeOf = require('../../../../helpers/rotation-aware-sizeof.js');
const path = require('path');
const normalizePath = require('normalize-path');

Expand Down
2 changes: 1 addition & 1 deletion app/back-end/modules/render-html/items/featured-image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
const sizeOf = require('image-size');
const sizeOf = require('./../../../helpers/rotation-aware-sizeof');
const URLHelper = require('./../helpers/url');
const ContentHelper = require('./../helpers/content');
const UtilsHelper = require('./../../../helpers/utils');
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/modules/render-html/renderer-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const normalizePath = require('normalize-path');
const Plugins = require('./../../plugins.js');
const RendererCache = require('./renderer-cache');
const RendererHelpers = require('./helpers/helpers.js');
const sizeOf = require('image-size');
const sizeOf = require('../../helpers/rotation-aware-sizeof.js');
const UtilsHelper = require('./../../helpers/utils');

/*
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/workers/thumbnails/post-images.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Image = require('./../../image.js');
const normalizePath = require('normalize-path');
const sizeOf = require('image-size');
const sizeOf = require('./../../helpers/rotation-aware-sizeof.js');

let result = false;
let appInstance = false;
Expand Down