Skip to content

Commit

Permalink
Merge pull request #86 from kochamaltki/pfp_resizing
Browse files Browse the repository at this point in the history
auto resize pfps
  • Loading branch information
malinowy5 authored May 29, 2024
2 parents 99b5aae + a3c2f86 commit 03a9819
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/api_calls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::database_functions::*;
use crate::types::*;
use crate::auth::*;
use crate::image_processing::*;
use bytes::BufMut;
use futures::{StreamExt, TryStreamExt};
use tracing::Instrument;
Expand Down Expand Up @@ -1716,6 +1717,7 @@ pub async fn upload_image(
error!("error writing file: {}", e);
warp::reject::reject()
})?;
crop_and_resize(pfp_file_name);
add_upload_db(&connection, token.claims.uid, 10).await;
info!("created file: {}", file_name);
return Ok(warp::reply::with_status(
Expand Down
10 changes: 5 additions & 5 deletions src/image_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use image::{GenericImageView, ImageFormat};
use image::imageops::{crop_imm, resize, FilterType};
use std::cmp::min;

pub fn crop_and_resize(filename: String) {
let img = image::open(format!("media/profile_pictures/{}", filename)).unwrap();
pub fn crop_and_resize(path: String) {
let img = image::open(path.clone()).unwrap();

let width = img.dimensions().0;
let height = img.dimensions().1;
Expand All @@ -15,12 +15,12 @@ pub fn crop_and_resize(filename: String) {
let cropped_img = crop_imm(&img, mid_x-temp_size/2, mid_y-temp_size/2, mid_x+temp_size/2, mid_y+temp_size/2);
cropped_img
.to_image()
.save_with_format(&format!("media/profile_pictures/{}", filename), ImageFormat::Png)
.save_with_format(&path, ImageFormat::Png)
.unwrap();

let img = image::open(format!("media/profile_pictures/{}", filename)).unwrap();
let img = image::open(path.clone()).unwrap();
let resized_img = resize(&img, 128, 128, FilterType::Lanczos3);

resized_img.save_with_format(&format!("media/profile_pictures/{}", filename), ImageFormat::Png).unwrap();
resized_img.save_with_format(&path, ImageFormat::Png).unwrap();

}

0 comments on commit 03a9819

Please sign in to comment.