Open brajabi opened 1 year ago
Thank you very much for sharing this code; it works really well.
I found there is a little typo, when orientation == 4
, it should be a vertical flip:
} else if orientation == 4 {
// filp V
img = DynamicImage::ImageRgba8(imageops::flip_vertical(&img));
I have referenced it to create a simplified version and applied it to Yazi (a terminal file manager with built-in image preview):
fn rotate(mut img: DynamicImage, orientation: u8) -> DynamicImage {
let rgba = img.color().has_alpha();
img = match orientation {
2 => DynamicImage::ImageRgba8(imageops::flip_horizontal(&img)),
3 => DynamicImage::ImageRgba8(imageops::rotate180(&img)),
4 => DynamicImage::ImageRgba8(imageops::flip_vertical(&img)),
5 => DynamicImage::ImageRgba8(imageops::flip_horizontal(&imageops::rotate90(&img))),
6 => DynamicImage::ImageRgba8(imageops::rotate90(&img)),
7 => DynamicImage::ImageRgba8(imageops::flip_horizontal(&imageops::rotate270(&img))),
8 => DynamicImage::ImageRgba8(imageops::rotate270(&img)),
_ => img,
};
if !rgba {
img = DynamicImage::ImageRgb8(img.into_rgb8());
}
img
}
Just leaving it here in case someone needs :)
thank you, it works...
I believe I have resolved the orientation issue. For more information on this topic, you can refer to the following article: https://magnushoff.com/articles/jpeg-orientation/
To recreate the issue, simply rotate a JPEG image on macOS, which will add orientation metadata to the EXIF data of the image.
The problem at hand is as follows :
this function will help you to get the orientation of image
and you can use it like this to get the right orientation at the end