mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 08:25:16 +00:00
Fix image rotation
This commit is contained in:
@ -5,6 +5,7 @@ use std::str::FromStr;
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use actix_web::http::{HeaderName, HeaderValue};
|
||||
use bytes::Bytes;
|
||||
use exif::In;
|
||||
use image::{GenericImageView, ImageFormat};
|
||||
use serde::Serialize;
|
||||
|
||||
@ -287,6 +288,39 @@ impl HttpRequestHandler {
|
||||
image = image.resize(max_w, max_h, image::imageops::FilterType::Nearest);
|
||||
}
|
||||
|
||||
// Read EXIF information in case of JPEG image, if possible
|
||||
if let Ok(ImageFormat::Jpeg) = image::guess_format(file.buff.as_ref()) {
|
||||
let mut reader = std::io::BufReader::new(file.buff.as_ref());
|
||||
|
||||
if let Ok(exif_attr) = exif::get_exif_attr_from_jpeg(&mut reader) {
|
||||
let exif_reader = exif::Reader::new();
|
||||
let exif = exif_reader.read_raw(exif_attr)?;
|
||||
|
||||
if let Some(v) = exif.get_field(exif::Tag::Orientation, In::PRIMARY) {
|
||||
match v.value.get_uint(0) {
|
||||
Some(1) => { /* row 0 is top and column 0 is left */ }
|
||||
//Some(2) => println!("row 0 at top and column 0 at right"),
|
||||
Some(3) => {
|
||||
/* row 0 at bottom and column 0 at right */
|
||||
image = image.rotate180()
|
||||
}
|
||||
//Some(4) => println!("row 0 at bottom and column 0 at left"),
|
||||
//Some(5) => println!("row 0 at left and column 0 at top"),
|
||||
Some(6) => {
|
||||
/* row 0 is right and column 0 is top */
|
||||
image = image.rotate90();
|
||||
}
|
||||
//Some(7) => println!("row 0 at right and column 0 at bottom"),
|
||||
Some(8) => {
|
||||
/* row 0 is left and column 0 is bottom */
|
||||
image = image.rotate270();
|
||||
}
|
||||
v => println!("Unhandled EXIF Orientation: {:?}", v),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Determine image destination
|
||||
let target_user_data_folder = prepare_file_creation(self.user_id()?, folder)?;
|
||||
|
Reference in New Issue
Block a user