Skip to content

Commit

Permalink
Fix image rotation being lost
Browse files Browse the repository at this point in the history
  • Loading branch information
Mosnar committed May 13, 2020
1 parent f0e305c commit e860fe7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "jest",
"docs": "serve ./docs"
},
"version": "2.0.4",
"version": "2.0.5",
"private": false,
"license": "MIT",
"dependencies": {},
Expand Down
16 changes: 8 additions & 8 deletions src/ImageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
}

/**
Expand Down

0 comments on commit e860fe7

Please sign in to comment.