@@ -40,11 +40,17 @@ pub enum ResponseImage {
4040
4141impl ProfileImage {
4242 pub fn new ( user_id : u32 ) -> Self {
43+ tracing:: debug!( "new user with id {user_id}" ) ;
4344 Self { user_id }
4445 }
4546
4647 pub async fn with_data ( self , data : & [ u8 ] ) -> Result < DataImage , AppError > {
4748 // save original
49+ tracing:: debug!(
50+ "saving original image on {} with data length {}" ,
51+ self . path_orig( ) . display( ) ,
52+ data. len( )
53+ ) ;
4854 let path = self . path_orig ( ) ;
4955 tokio:: fs:: write ( path, data) . await ?;
5056
@@ -82,6 +88,7 @@ impl ProfileImage {
8288impl DataImage {
8389 /// save as multiple sizes
8490 pub async fn save_sizes ( self , sizes : & [ u32 ] ) -> Result < ( ) , AppError > {
91+ tracing:: debug!( "saving images with sizes {:?}" , sizes) ;
8592 let mut set = JoinSet :: new ( ) ;
8693 let image = Arc :: new ( self ) ;
8794
@@ -100,30 +107,42 @@ impl DataImage {
100107 /// resize the image and save
101108 pub async fn save_size ( & self , size : u32 ) -> Result < ( ) , AppError > {
102109 // magick 102 -coalesce -resize "64x64^" -gravity center -crop "64x64+0+0" +repage out.webp
110+ let orig_path = self . profile . path_orig ( ) ;
111+ let sized_path = self . profile . path ( size) ;
112+ let resize_arg = format ! ( "{size}x{size}^" ) ;
113+ let crop_arg = format ! ( "{size}x{size}+0+0" ) ;
114+
115+ let args = [
116+ orig_path
117+ . to_str ( )
118+ . ok_or ( AppError :: Internal ( "invalid path" . into ( ) ) ) ?,
119+ "-coalesce" ,
120+ "-filter" ,
121+ "Robidoux" ,
122+ "-resize" ,
123+ resize_arg. as_str ( ) ,
124+ "-gravity" ,
125+ "center" ,
126+ "-crop" ,
127+ crop_arg. as_str ( ) ,
128+ "+repage" ,
129+ sized_path
130+ . to_str ( )
131+ . ok_or ( AppError :: Internal ( "invalid path" . into ( ) ) ) ?,
132+ ] ;
133+
134+ tracing:: debug!(
135+ "running command {} with args {:?}" ,
136+ MAGICK_PATH . as_str( ) ,
137+ args
138+ ) ;
139+
103140 let output = Command :: new ( MAGICK_PATH . as_str ( ) )
104- . args ( [
105- self . profile
106- . path_orig ( )
107- . to_str ( )
108- . ok_or ( AppError :: Internal ( "invalid path" . into ( ) ) ) ?,
109- "-coalesce" ,
110- "-filter" ,
111- "Robidoux" ,
112- "-resize" ,
113- format ! ( "{size}x{size}^" ) . as_str ( ) ,
114- "-gravity" ,
115- "center" ,
116- "-crop" ,
117- format ! ( "{size}x{size}+0+0" ) . as_str ( ) ,
118- "+repage" ,
119- self . profile
120- . path ( size)
121- . to_str ( )
122- . ok_or ( AppError :: Internal ( "invalid path" . into ( ) ) ) ?,
123- ] )
141+ . args ( args)
124142 . output ( )
125143 . await ?;
126144
145+ tracing:: debug!( "command ran with status code {}" , output. status) ;
127146 // if magick was not success
128147 if !output. status . success ( ) {
129148 return Err ( AppError :: Magick (
0 commit comments