From 9052559f434349d42d7802f36be0863d8d7e304d Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Wed, 6 Nov 2024 16:06:16 +0100 Subject: [PATCH] fixed aspect ratio for image with exif orientation tag #2316 --- CHANGELOG.md | 4 ++++ src/imageMeasure.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84ba862f7..46733ce16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Fixed aspect ratio for image with exif orientation tag + ## 0.2.15 - 2024-11-02 - Added support PDF/A and PDF/UA (see [documentation](https://pdfmake.github.io/docs/0.1/document-definition-object/pdfa/)) diff --git a/src/imageMeasure.js b/src/imageMeasure.js index 5ad647be9..034385d00 100644 --- a/src/imageMeasure.js +++ b/src/imageMeasure.js @@ -26,7 +26,16 @@ ImageMeasure.prototype.measureImage = function (src) { image = this.pdfKitDoc._imageRegistry[src]; } - return { width: image.width, height: image.height }; + var imageSize = { width: image.width, height: image.height }; + + if (typeof image === 'object' && image.constructor.name === 'JPEG') { + // If EXIF orientation calls for it, swap width and height + if (image.orientation > 4) { + imageSize = { width: image.height, height: image.width }; + } + } + + return imageSize; function realImageSrc(src) { var img = that.imageDictionary[src];