mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Resize image only if required
This commit is contained in:
parent
ac469f86e8
commit
83492f6c8d
@ -5,7 +5,7 @@ use std::str::FromStr;
|
|||||||
use actix_web::{HttpRequest, HttpResponse, web};
|
use actix_web::{HttpRequest, HttpResponse, web};
|
||||||
use actix_web::http::{HeaderName, HeaderValue};
|
use actix_web::http::{HeaderName, HeaderValue};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use image::ImageFormat;
|
use image::{GenericImageView, ImageFormat};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::api_data::http_error::HttpError;
|
use crate::api_data::http_error::HttpError;
|
||||||
@ -281,8 +281,11 @@ impl HttpRequestHandler {
|
|||||||
|
|
||||||
// Load image
|
// Load image
|
||||||
let file = self.post_file(name)?;
|
let file = self.post_file(name)?;
|
||||||
let image = image::load_from_memory(file.buff.as_ref())?;
|
let mut image = image::load_from_memory(file.buff.as_ref())?;
|
||||||
let image = image.resize(max_w, max_h, image::imageops::FilterType::Nearest);
|
|
||||||
|
if image.width() > max_w || image.height() > max_h {
|
||||||
|
image = image.resize(max_w, max_h, image::imageops::FilterType::Nearest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Determine image destination
|
// Determine image destination
|
||||||
|
Loading…
Reference in New Issue
Block a user