Upload width and height of image with other data
This commit is contained in:
parent
dd2748cbe0
commit
faa8776740
|
@ -14,4 +14,6 @@ message Image {
|
|||
string thumb_url = 3;
|
||||
string blurhash = 4;
|
||||
Format format = 5;
|
||||
uint32 width = 6;
|
||||
uint32 height = 7;
|
||||
}
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -96,16 +96,17 @@ fn create(server: &str, args: CreateArgs) {
|
|||
.inspect(|r| if r.is_ok() { print!("\x1b[32mDone!\n\x1b[37m├─\x1b[0m Thumbnailing... ") })
|
||||
.inspect(|_| drop(stdout().flush()))
|
||||
.map(|r| r.and_then(|(path, raw_dat)| {
|
||||
let (full, thumbnail, blurhash, format) = thumbnailing::thumbnail(&raw_dat)
|
||||
let (full, w, h, thumbnail, blurhash, format) = thumbnailing::thumbnail(&raw_dat)
|
||||
.map_err(|_| AviaryUploadError::ImageFormatError(path.to_owned()))?;
|
||||
Ok((full.map(Either::Right).unwrap_or(Either::Left(raw_dat)), thumbnail, blurhash, format))
|
||||
Ok((full.map(Either::Right).unwrap_or(Either::Left(raw_dat)), w, h, thumbnail, blurhash, format))
|
||||
}))
|
||||
.inspect(|r| if r.is_ok() { print!("\x1b[32mDone!\n\x1b[37m├─\x1b[0m Encrypting... ")})
|
||||
.inspect(|_| drop(stdout().flush()))
|
||||
.map_ok(|(raw_dat, thumbnail, blurhash, format)| {
|
||||
.map_ok(|(raw_dat, w, h, thumbnail, blurhash, format)| {
|
||||
let key = crypto::make_key();
|
||||
(
|
||||
key,
|
||||
w, h,
|
||||
crypto::encrypt(&key, &crypto::NONCE_A, &raw_dat),
|
||||
crypto::encrypt(&key, &crypto::NONCE_B, &thumbnail),
|
||||
blurhash,
|
||||
|
@ -114,27 +115,27 @@ fn create(server: &str, args: CreateArgs) {
|
|||
})
|
||||
.inspect(|r| if r.is_ok() { print!("\x1b[32mDone!\n\x1b[37m└─\x1b[0m Uploading... ")})
|
||||
.inspect(|_| drop(stdout().flush()))
|
||||
.map(|r| r.and_then(|(key, full_img, thumb, blurhash, format)|
|
||||
.map(|r| r.and_then(|(key, w, h, full_img, thumb, blurhash, format)|
|
||||
upload::put_data(&agent, server, &thumb)
|
||||
.and_then(|thumb_url|
|
||||
upload::put_data(&agent, server, &full_img)
|
||||
.map(|full_url| (key, full_url, thumb_url, blurhash, format)))
|
||||
.map(|full_url| (key, w, h, full_url, thumb_url, blurhash, format)))
|
||||
.map_err(AviaryUploadError::from_upload_error)
|
||||
))
|
||||
.map(|r| r.and_then(|(key, full_url, thumb_url, blurhash, format)| {
|
||||
.map(|r| r.and_then(|(key, w, h, full_url, thumb_url, blurhash, format)| {
|
||||
let full_trimmed = trim_url(server, &full_url);
|
||||
let thmb_trimmed = trim_url(server, &thumb_url);
|
||||
if let (Some(full_url), Some(thmb_url)) = (full_trimmed, thmb_trimmed) {
|
||||
Ok((key, full_url.to_owned(), thmb_url.to_owned(), blurhash, format))
|
||||
Ok((key, w, h, full_url.to_owned(), thmb_url.to_owned(), blurhash, format))
|
||||
} else {
|
||||
Err(AviaryUploadError::ServerError(format!("Received bad response from server: {}", full_url)))
|
||||
}
|
||||
}))
|
||||
.inspect(|r| if r.is_ok() { println!("\x1b[32mDone!\n")})
|
||||
.map_ok(|(key, full_url, thumb_url, blurhash, format)| protobuf::image::Image {
|
||||
.map_ok(|(key, width, height, full_url, thumb_url, blurhash, format)| protobuf::image::Image {
|
||||
key: key.into(),
|
||||
format: format.into(),
|
||||
full_url, thumb_url, blurhash,
|
||||
width, height, full_url, thumb_url, blurhash,
|
||||
special_fields: Default::default()
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
|
|
|
@ -4,7 +4,7 @@ use webp::{Encoder, WebPMemory};
|
|||
|
||||
use crate::protobuf::image::Format;
|
||||
|
||||
pub fn thumbnail(bytes: &[u8]) -> ImageResult<(Option<WebPMemory>, WebPMemory, String, Format)> {
|
||||
pub fn thumbnail(bytes: &[u8]) -> ImageResult<(Option<WebPMemory>, u32, u32, WebPMemory, String, Format)> {
|
||||
let original_image_encoded = Reader::new(Cursor::new(bytes))
|
||||
.with_guessed_format().expect("IO errors impossible with Cursor");
|
||||
let original_format = original_image_encoded.format();
|
||||
|
@ -41,6 +41,8 @@ pub fn thumbnail(bytes: &[u8]) -> ImageResult<(Option<WebPMemory>, WebPMemory, S
|
|||
|
||||
Ok((
|
||||
recoded_original,
|
||||
original_image.width(),
|
||||
original_image.height(),
|
||||
Encoder::from_image(&DynamicImage::ImageRgba8(scaled))
|
||||
.expect("Unexpected difficulty interpretting thumbnail")
|
||||
.encode(50.0),
|
||||
|
|
Loading…
Reference in a new issue