putz u in dhe washing machin and spins ur bsky pofile pictuer !!! :D

custom background color wattt dat so cool !! #2

merged opened by koi.rip targeting main from koi.rip/washng0machine: push-kvolytsvonws
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:b26ewgkrnx3yvsp2cdao3ntu/sh.tangled.repo.pull/3mcclrsxi2s22
+40 -9
Diff #0
+1
README.md
··· 20 20 screen 21 21 export IDENTIFIER="your-handle-or-did" 22 22 export APP_PASSWORD="your-app-password" 23 + export BACKGROUND="d0c1f5ff" # hex rgba, optional 23 24 24 25 watch -n 60 ./washing-machien /path/to/your/image.jpg 25 26 ```
+39 -9
src/main.rs
··· 43 43 eprintln!("environment variables:"); 44 44 eprintln!(" APP_PASSWORD"); 45 45 eprintln!(" IDENTIFIER - your handle or did"); 46 + eprintln!(" BACKGROUND - rgba hex background color to use (default is 00000000)"); 46 47 process::exit(1); 47 48 } 48 49 ··· 66 67 ((angle % 360) + 360) % 360 67 68 } 68 69 69 - fn rotate_image(image: DynamicImage, degrees: i32) -> image::RgbaImage { 70 + fn rotate_image(image: DynamicImage, degrees: i32, bg_color: image::Rgba<u8>) -> image::RgbaImage { 70 71 let width = image.width(); 71 72 let height = image.height(); 72 73 ··· 77 78 (width as f32 / 2.0, height as f32 / 2.0), 78 79 radians, 79 80 Interpolation::Bilinear, 80 - image::Rgba([0, 0, 0, 0]), 81 + bg_color, 81 82 ); 82 83 83 84 rotated ··· 120 121 println!("successfully updated avatar"); 121 122 } 122 123 123 - fn required_env(var: &str, exe: &str) -> String { 124 + fn env(var: &str, default: Option<&str>, exe: &str) -> String { 124 125 match env::var(var) { 125 126 Ok(v) if !v.trim().is_empty() => v, 126 127 _ => { 127 - eprintln!("env variable {} not set or empty", var); 128 - print_usage(exe); 129 - process::exit(1); 128 + if let Some(def) = default { 129 + return def.to_string(); 130 + } else { 131 + eprintln!("env variable {} not set or empty", var); 132 + print_usage(exe); 133 + process::exit(1); 134 + } 130 135 } 131 136 } 132 137 } 133 138 139 + fn hex_to_rgba(hex: String) -> image::Rgba<u8> { 140 + let hex = hex.trim_start_matches('#'); 141 + 142 + let (r, g, b, a) = match hex.len() { 143 + 6 => ( 144 + u8::from_str_radix(&hex[0..2], 16).unwrap(), 145 + u8::from_str_radix(&hex[2..4], 16).unwrap(), 146 + u8::from_str_radix(&hex[4..6], 16).unwrap(), 147 + 255, 148 + ), 149 + 8 => ( 150 + u8::from_str_radix(&hex[0..2], 16).unwrap(), 151 + u8::from_str_radix(&hex[2..4], 16).unwrap(), 152 + u8::from_str_radix(&hex[4..6], 16).unwrap(), 153 + u8::from_str_radix(&hex[6..8], 16).unwrap(), 154 + ), 155 + _ => panic!("Invalid hex color"), 156 + }; 157 + 158 + image::Rgba([r, g, b, a]) 159 + } 160 + 134 161 #[tokio::main] 135 162 async fn main() { 136 163 let mut args = env::args(); ··· 145 172 }; 146 173 let output = args.next(); 147 174 148 - let app_password = required_env("APP_PASSWORD", &executable); 149 - let identifier = required_env("IDENTIFIER", &executable); 175 + let app_password = env("APP_PASSWORD", None, &executable); 176 + let identifier = env("IDENTIFIER", None, &executable); 177 + let bg_color = env("BACKGROUND", Some("00000000"), &executable); 150 178 151 179 let (session, auth) = MemoryCredentialSession::authenticated( 152 180 identifier.to_cowstr(), ··· 185 213 return; 186 214 } 187 215 } 188 - let rotated = rotate_image(image, angle); 216 + 217 + let bg_color_rgba = hex_to_rgba(bg_color); 218 + let rotated = rotate_image(image, angle, bg_color_rgba); 189 219 190 220 if let Some(out) = &output { 191 221 rotated.save(out).unwrap_or_else(|e| {

History

1 round 1 comment
sign up or login to add to the discussion
koi.rip submitted #0
1 commit
expand
custom background color wattt dat so cool !!
expand 1 comment
pull request successfully merged