I have a bunch of photos from my old iPad. I have a script that create thumbnail photos from these images.
The goal is to resize the image into 150x125 and crop if necessary to achieve the result.
const options: ResizeOptions = {
width: 150,
height: 125,
fit: 'cover',
}
await sharp(inFile).resize(options).toFile(outFile);
It works fine on landscape images. For some reason, portrait thumbnails are rotated as if it is adjusted to fit the given 150x125 dimension.
Found a related issue on github:
Turns out, sharp automatically rotates the image due to some EXIF metadata from my iPad photos.
I don't dig deeper EXIF stuff and jump straight to solution.
The trick is to rotate the image first based on EXIF orientation then resize.
const options: ResizeOptions = {
width: 150,
height: 125,
fit: 'cover',
}
await sharp(inFile).rotate().resize(options).toFile(outFile);
Pro tip!
If you can't find the Github issue of a certain repo, try searching it on the "closed" issues.