Created
September 29, 2022 16:00
-
-
Save asilvas-godaddy/2430fb186c51407ccb90b2900c7fd64a to your computer and use it in GitHub Desktop.
sharp v0.31.1 bug with rotatiion+resize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sharp = require('sharp'); | |
const fs = require('fs/promises'); | |
// any orientation 5 image should suffice but can download from https://drive.google.com/file/d/176GYzVQ_bj0X57CvZS5CfgiZzFjTAkMl/view?usp=sharing | |
const FILE_IN = 'Portrait_5.jpg'; | |
const FILE_OUT_ROTATED = 'Portrait_5_rotated.jpg'; | |
const FILE_OUT_RESIZED = 'Portrait_5_rotated_resized.jpg'; | |
(async () => { | |
const origBytes = await fs.readFile(FILE_IN); | |
// https://sirv.com/help/articles/rotate-photos-to-be-upright | |
const rotated = sharp(origBytes).flip().rotate(90); | |
const rotatedBytes = await rotated.toBuffer(); | |
await fs.writeFile(FILE_OUT_ROTATED, rotatedBytes); | |
// resize is changing the rotation for some reason | |
const resized = sharp(origBytes).flip().rotate(90).resize(320, 427); | |
const resizedBytes = await resized.toBuffer(); | |
await fs.writeFile(FILE_OUT_RESIZED, resizedBytes); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment