From f5fb529243092c87ce8895398da41e38f24c073e Mon Sep 17 00:00:00 2001 From: Phillip Pearson Date: Wed, 19 Feb 2025 22:25:39 -0800 Subject: [PATCH 1/5] fix: Handle EXIF orientation in uploaded gallery images (#1617, #1694). Photoswipe needs correct width and height information for all images, or it will show them stretched to an incorrect aspect ratio. When an image is uploaded with an EXIF orientation of 6 or 8 (rotated +90 or -90 degrees), the width and height need to be swapped. Add helpers/rotation-aware-sizeof.js, which wraps the image-size module and swaps width and height if necessary. --- app/back-end/helpers/avatar.js | 2 +- app/back-end/helpers/rotation-aware-sizeof.js | 30 +++++++++++++++++++ app/back-end/image.js | 2 +- .../render-html/contexts/page-preview.js | 2 +- .../render-html/contexts/post-preview.js | 2 +- .../handlebars/helpers/image-dimensions.js | 2 +- .../render-html/handlebars/helpers/json-ld.js | 2 +- .../handlebars/helpers/social-meta-tags.js | 2 +- .../render-html/items/featured-image.js | 2 +- .../modules/render-html/renderer-context.js | 2 +- .../workers/thumbnails/post-images.js | 2 +- 11 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 app/back-end/helpers/rotation-aware-sizeof.js diff --git a/app/back-end/helpers/avatar.js b/app/back-end/helpers/avatar.js index ae1801cac..1acc9351c 100644 --- a/app/back-end/helpers/avatar.js +++ b/app/back-end/helpers/avatar.js @@ -1,4 +1,4 @@ -const sizeOf = require('image-size'); +const sizeOf = require('./rotation-aware-sizeof.js'); class AvatarHelper { /* diff --git a/app/back-end/helpers/rotation-aware-sizeof.js b/app/back-end/helpers/rotation-aware-sizeof.js new file mode 100644 index 000000000..b00dd7024 --- /dev/null +++ b/app/back-end/helpers/rotation-aware-sizeof.js @@ -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; diff --git a/app/back-end/image.js b/app/back-end/image.js index 87e81158b..5817c39a8 100644 --- a/app/back-end/image.js +++ b/app/back-end/image.js @@ -7,7 +7,7 @@ const fs = require('fs-extra'); const os = require('os'); 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'); diff --git a/app/back-end/modules/render-html/contexts/page-preview.js b/app/back-end/modules/render-html/contexts/page-preview.js index a56b49e54..34122350a 100644 --- a/app/back-end/modules/render-html/contexts/page-preview.js +++ b/app/back-end/modules/render-html/contexts/page-preview.js @@ -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'); diff --git a/app/back-end/modules/render-html/contexts/post-preview.js b/app/back-end/modules/render-html/contexts/post-preview.js index d9d386f6e..79d5c2b62 100644 --- a/app/back-end/modules/render-html/contexts/post-preview.js +++ b/app/back-end/modules/render-html/contexts/post-preview.js @@ -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'); diff --git a/app/back-end/modules/render-html/handlebars/helpers/image-dimensions.js b/app/back-end/modules/render-html/handlebars/helpers/image-dimensions.js index d1dbd38b5..70a2c1275 100644 --- a/app/back-end/modules/render-html/handlebars/helpers/image-dimensions.js +++ b/app/back-end/modules/render-html/handlebars/helpers/image-dimensions.js @@ -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'); diff --git a/app/back-end/modules/render-html/handlebars/helpers/json-ld.js b/app/back-end/modules/render-html/handlebars/helpers/json-ld.js index 435c105d8..75ead82b8 100644 --- a/app/back-end/modules/render-html/handlebars/helpers/json-ld.js +++ b/app/back-end/modules/render-html/handlebars/helpers/json-ld.js @@ -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'); diff --git a/app/back-end/modules/render-html/handlebars/helpers/social-meta-tags.js b/app/back-end/modules/render-html/handlebars/helpers/social-meta-tags.js index ba331b9b8..f9df9c088 100644 --- a/app/back-end/modules/render-html/handlebars/helpers/social-meta-tags.js +++ b/app/back-end/modules/render-html/handlebars/helpers/social-meta-tags.js @@ -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'); diff --git a/app/back-end/modules/render-html/items/featured-image.js b/app/back-end/modules/render-html/items/featured-image.js index dbcf72688..ffebde0c9 100644 --- a/app/back-end/modules/render-html/items/featured-image.js +++ b/app/back-end/modules/render-html/items/featured-image.js @@ -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'); diff --git a/app/back-end/modules/render-html/renderer-context.js b/app/back-end/modules/render-html/renderer-context.js index 2f5134ccf..891dbe395 100644 --- a/app/back-end/modules/render-html/renderer-context.js +++ b/app/back-end/modules/render-html/renderer-context.js @@ -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'); /* diff --git a/app/back-end/workers/thumbnails/post-images.js b/app/back-end/workers/thumbnails/post-images.js index ead4351d5..f23f788f9 100644 --- a/app/back-end/workers/thumbnails/post-images.js +++ b/app/back-end/workers/thumbnails/post-images.js @@ -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; From bb018023ead3e85ce2a30cb3c5da4794e4d371bf Mon Sep 17 00:00:00 2001 From: Phillip Pearson Date: Sat, 27 Sep 2025 21:52:42 -0700 Subject: [PATCH 2/5] Build for Brittany (with splash screen msg) -- now using Node 24 - brittany_build.sh builds the whole thing. - dev.sh preps everything and starts the dev version. - clean.sh cleans up if you're getting weird build issues. --- app/src/components/Splashscreen.vue | 2 ++ brittany_build.sh | 14 ++++++++++++++ clean.sh | 7 +++++++ dev.sh | 18 ++++++++++++++++++ package.json | 1 + setup_correct_node.sh | 4 ++++ 6 files changed, 46 insertions(+) create mode 100755 brittany_build.sh create mode 100755 clean.sh create mode 100755 dev.sh create mode 100644 setup_correct_node.sh diff --git a/app/src/components/Splashscreen.vue b/app/src/components/Splashscreen.vue index 644237068..04e1eb69f 100644 --- a/app/src/components/Splashscreen.vue +++ b/app/src/components/Splashscreen.vue @@ -5,6 +5,8 @@ +

philandbrittany.com edition -- with image aspect ratio fixes.

+ v.{{ version }} (build {{ build }}) diff --git a/brittany_build.sh b/brittany_build.sh new file mode 100755 index 000000000..1447c3a03 --- /dev/null +++ b/brittany_build.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -euo pipefail + +source setup_correct_node.sh + +npm install +(cd app; npm install) + +rm -rf dist +npm run packager:mac-m + +DEST="$HOME/Dropbox/brittany/Publii-for-Brittany.app" +rm -rf "$DEST" +cp -av dist/mac-arm64/Publii.app "$DEST" diff --git a/clean.sh b/clean.sh new file mode 100755 index 000000000..b10eb7dce --- /dev/null +++ b/clean.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -euo pipefail + +for d in . app; do + rm -vrf $d/node_modules $d/package-lock.json +done + diff --git a/dev.sh b/dev.sh new file mode 100755 index 000000000..22f9c4a1f --- /dev/null +++ b/dev.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -euo pipefail + +source setup_correct_node.sh + +echo "Installing node modules in ./" +npm install +echo "Installing node modules in ./app" +(cd app; npm install) +echo "Running npm run dev-prep" +npm run dev-prep + +echo "Running npm run dev in the background" +npm run dev & +echo "Running npm run prepare-editor" +npm run prepare-editor +echo "Running npm run build, which should start the app" +npm run build diff --git a/package.json b/package.json index baf0c362c..b776f33b8 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "main": "app/main.js", "scripts": { "dev": "cross-env NODE_ENV=development webpack --mode=development --progress --watch", + "dev-prep": "cross-env NODE_ENV=development webpack --mode=development --progress", "prod": "cross-env NODE_ENV=production webpack --mode=production --progress", "build": "node ./build/scripts/update-build-number.js && cross-env NODE_ENV=development ./node_modules/.bin/electron app/", "build2": "cross-env NODE_ENV=development ./node_modules/.bin/electron app/", diff --git a/setup_correct_node.sh b/setup_correct_node.sh new file mode 100644 index 000000000..0e304f9bb --- /dev/null +++ b/setup_correct_node.sh @@ -0,0 +1,4 @@ +NODEVERSION=24 +export PATH="/opt/homebrew/opt/node@${NODEVERSION}/bin:$PATH" +export LDFLAGS="-L/opt/homebrew/opt/node@${NODEVERSION}/lib" +export CPPFLAGS="-I/opt/homebrew/opt/node@${NODEVERSION}/include" From 1249282cdeb85341012e9c8e4353d34d68733a3c Mon Sep 17 00:00:00 2001 From: Phillip Pearson Date: Sat, 27 Sep 2025 22:57:04 -0700 Subject: [PATCH 3/5] Install @emnapi/runtime, because we seem to need it --- app/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/app/package.json b/app/package.json index 2237b22c9..bfd206adb 100644 --- a/app/package.json +++ b/app/package.json @@ -26,6 +26,7 @@ "homepage": "https://getpublii.com", "dependencies": { "@aws-sdk/client-s3": "3.623.0", + "@emnapi/runtime": "^1.5.0", "@gitbeaker/node": "35.8.1", "@google-cloud/storage": "6.11.0", "@octokit/rest": "22.0.0", From b481df9d59a96c03935e924cdac093e699e8f024 Mon Sep 17 00:00:00 2001 From: Phillip Pearson Date: Sat, 27 Sep 2025 23:23:26 -0700 Subject: [PATCH 4/5] Back to Node 20; this seems to build and run OK --- brittany_build.sh | 6 ++++++ clean.sh | 3 ++- setup_correct_node.sh | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/brittany_build.sh b/brittany_build.sh index 1447c3a03..db4100028 100755 --- a/brittany_build.sh +++ b/brittany_build.sh @@ -3,9 +3,15 @@ set -euo pipefail source setup_correct_node.sh +echo "Killing any stray webpack processes" +pkill webpack || true + +echo "Running npm install" +rm -vf package-lock.json app/package-lock.json npm install (cd app; npm install) +echo "Running packager" rm -rf dist npm run packager:mac-m diff --git a/clean.sh b/clean.sh index b10eb7dce..03ec48b80 100755 --- a/clean.sh +++ b/clean.sh @@ -2,6 +2,7 @@ set -euo pipefail for d in . app; do - rm -vrf $d/node_modules $d/package-lock.json + rm -vrf $d/node_modules + git checkout $d/package-lock.json done diff --git a/setup_correct_node.sh b/setup_correct_node.sh index 0e304f9bb..791a387e9 100644 --- a/setup_correct_node.sh +++ b/setup_correct_node.sh @@ -1,4 +1,4 @@ -NODEVERSION=24 +NODEVERSION=20 export PATH="/opt/homebrew/opt/node@${NODEVERSION}/bin:$PATH" export LDFLAGS="-L/opt/homebrew/opt/node@${NODEVERSION}/lib" export CPPFLAGS="-I/opt/homebrew/opt/node@${NODEVERSION}/include" From d8f8d52029f30c4f5cfe6acc47ad9216cae8aa1d Mon Sep 17 00:00:00 2001 From: Phillip Pearson Date: Sat, 27 Sep 2025 23:38:21 -0700 Subject: [PATCH 5/5] Looks like maybe the problem was that I needed to run prod and prepare-editor before the big build? Back to Node 24. --- brittany_build.sh | 6 ++++++ setup_correct_node.sh | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/brittany_build.sh b/brittany_build.sh index db4100028..f88024317 100755 --- a/brittany_build.sh +++ b/brittany_build.sh @@ -11,6 +11,12 @@ rm -vf package-lock.json app/package-lock.json npm install (cd app; npm install) +echo "Running npm run prod" +npm run prod + +echo "Running npm run prepare-editor" +npm run prepare-editor + echo "Running packager" rm -rf dist npm run packager:mac-m diff --git a/setup_correct_node.sh b/setup_correct_node.sh index 791a387e9..0e304f9bb 100644 --- a/setup_correct_node.sh +++ b/setup_correct_node.sh @@ -1,4 +1,4 @@ -NODEVERSION=20 +NODEVERSION=24 export PATH="/opt/homebrew/opt/node@${NODEVERSION}/bin:$PATH" export LDFLAGS="-L/opt/homebrew/opt/node@${NODEVERSION}/lib" export CPPFLAGS="-I/opt/homebrew/opt/node@${NODEVERSION}/include"