Skip to content

Commit

Permalink
fix(gatsby-plugin-sharp): Image rotation (#14302)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgw authored and wardpeet committed May 28, 2019
1 parent ade2098 commit 5e4bf34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ async function generateBase64({ file, args, reporter }) {
})
let pipeline
try {
pipeline = sharp(file.absolutePath).rotate()
pipeline = sharp(file.absolutePath)

if (!options.rotate) {
pipeline.rotate()
}
} catch (err) {
reportError(`Failed to process image ${file.absolutePath}`, err, reporter)
return null
Expand Down
6 changes: 4 additions & 2 deletions packages/gatsby-plugin-sharp/src/process-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ exports.processFile = (file, transforms, options = {}) => {
if (!options.stripMetadata) {
pipeline = pipeline.withMetadata()
}

pipeline = pipeline.rotate()
} catch (err) {
throw new Error(`Failed to process image ${file}`)
}
Expand All @@ -91,6 +89,10 @@ exports.processFile = (file, transforms, options = {}) => {

let clonedPipeline = transforms.length > 1 ? pipeline.clone() : pipeline

if (!args.rotate) {
clonedPipeline = clonedPipeline.rotate()
}

// Sharp only allows ints as height/width. Since both aren't always
// set, check first before trying to round them.
let roundedHeight = args.height
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-plugin-sharp/src/trace-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ exports.notMemoizedPrepareTraceSVGInputFile = async ({
}) => {
let pipeline
try {
pipeline = sharp(file.absolutePath).rotate()
pipeline = sharp(file.absolutePath)

if (!options.rotate) {
pipeline.rotate()
}
} catch (err) {
reportError(`Failed to process image ${file.absolutePath}`, err, reporter)
return
Expand Down

0 comments on commit 5e4bf34

Please sign in to comment.