diff --git a/CHANGELOG.md b/CHANGELOG.md index 65e6644..2c85e9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.0.3.1] - 2020-05-04 +## [2.0.5] - 2020-05-13 + +### Fixed +- Fixed bug where an image that is rotated with EXIF data loses its rotation (#67) + +## [2.0.4] - 2020-05-04 + +No changes + +## [2.0.3] - 2020-05-04 ### Fixed - Fixed bug with Serverless not excluding dev-dependencies and failing to deploy due to large file size diff --git a/package.json b/package.json index 9e731cc..7eb8f89 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test": "jest", "docs": "serve ./docs" }, - "version": "2.0.4", + "version": "2.0.5", "private": false, "license": "MIT", "dependencies": {}, diff --git a/src/ImageHandler.js b/src/ImageHandler.js index 0f64a43..1f3900f 100644 --- a/src/ImageHandler.js +++ b/src/ImageHandler.js @@ -36,10 +36,12 @@ class ImageHandler { // We have some edits to process if (Object.keys(this.request.edits).length) { try { - const modifiedImage = await this.applyEdits(originalImageBody, this.request.edits) - const optimizedImage = await this.applyOptimizations(modifiedImage) - bufferImage = await optimizedImage.toBuffer() - format = optimizedImage.options.formatOut + // We're calling rotate on this immediately in order to ensure metadata for rotation doesn't get lost + const pipeline = sharp(originalImageBody).rotate() + await this.applyEdits(pipeline, this.request.edits) + await this.applyOptimizations(pipeline) + bufferImage = await pipeline.toBuffer() + format = pipeline.options.formatOut } catch (err) { console.error('Unhandlable image encountered', err) bufferImage = Buffer.from(originalImageBody, 'binary') @@ -80,14 +82,12 @@ class ImageHandler { /** * Applies image modifications to the original image based on edits * specified in the ImageRequest. - * @param {Buffer} originalImage - The original image. + * @param {sharp} originalImage - The original image. * @param {Object} edits - The edits to be made to the original image. */ - async applyEdits (originalImage, edits) { - const image = sharp(originalImage) + async applyEdits (image, edits) { await imageOps.restrictSize(image, await image.metadata()) await imageOps.apply(image, edits) - return image } /**