pict-rs/src/discover/exiftool.rs

51 lines
1.1 KiB
Rust
Raw Normal View History

use actix_web::web::Bytes;
use crate::{
exiftool::ExifError,
formats::{ImageInput, InputFile},
process::Process,
};
use super::Discovery;
2023-12-16 04:34:45 +00:00
#[tracing::instrument(level = "debug", skip_all)]
pub(super) async fn check_reorient(
Discovery {
input,
width,
height,
frames,
}: Discovery,
2023-08-05 17:41:06 +00:00
timeout: u64,
bytes: Bytes,
) -> Result<Discovery, ExifError> {
let input = match input {
InputFile::Image(ImageInput { format, .. }) => {
2023-08-05 17:41:06 +00:00
let needs_reorient = needs_reorienting(bytes, timeout).await?;
InputFile::Image(ImageInput {
format,
needs_reorient,
})
}
otherwise => otherwise,
};
Ok(Discovery {
input,
width,
height,
frames,
})
}
2023-12-16 04:34:45 +00:00
#[tracing::instrument(level = "trace", skip_all)]
2023-08-05 17:41:06 +00:00
async fn needs_reorienting(input: Bytes, timeout: u64) -> Result<bool, ExifError> {
let buf = Process::run("exiftool", &["-n", "-Orientation", "-"], &[], timeout)?
.bytes_read(input)
.to_string()
.await?;
Ok(!buf.is_empty())
}