Skip to content

Commit 5e4bf34

Browse files
cwgwwardpeet
authored andcommitted
fix(gatsby-plugin-sharp): Image rotation (#14302)
1 parent ade2098 commit 5e4bf34

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

packages/gatsby-plugin-sharp/src/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ async function generateBase64({ file, args, reporter }) {
144144
})
145145
let pipeline
146146
try {
147-
pipeline = sharp(file.absolutePath).rotate()
147+
pipeline = sharp(file.absolutePath)
148+
149+
if (!options.rotate) {
150+
pipeline.rotate()
151+
}
148152
} catch (err) {
149153
reportError(`Failed to process image ${file.absolutePath}`, err, reporter)
150154
return null

packages/gatsby-plugin-sharp/src/process-file.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ exports.processFile = (file, transforms, options = {}) => {
7979
if (!options.stripMetadata) {
8080
pipeline = pipeline.withMetadata()
8181
}
82-
83-
pipeline = pipeline.rotate()
8482
} catch (err) {
8583
throw new Error(`Failed to process image ${file}`)
8684
}
@@ -91,6 +89,10 @@ exports.processFile = (file, transforms, options = {}) => {
9189

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

92+
if (!args.rotate) {
93+
clonedPipeline = clonedPipeline.rotate()
94+
}
95+
9496
// Sharp only allows ints as height/width. Since both aren't always
9597
// set, check first before trying to round them.
9698
let roundedHeight = args.height

packages/gatsby-plugin-sharp/src/trace-svg.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ exports.notMemoizedPrepareTraceSVGInputFile = async ({
1616
}) => {
1717
let pipeline
1818
try {
19-
pipeline = sharp(file.absolutePath).rotate()
19+
pipeline = sharp(file.absolutePath)
20+
21+
if (!options.rotate) {
22+
pipeline.rotate()
23+
}
2024
} catch (err) {
2125
reportError(`Failed to process image ${file.absolutePath}`, err, reporter)
2226
return

0 commit comments

Comments
 (0)