initial commit
This commit is contained in:
commit
a546389caa
4 changed files with 967 additions and 0 deletions
56
src/main.rs
Normal file
56
src/main.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
use photon_rs::{
|
||||
PhotonImage, multiple::watermark, native::open_image, native::save_image, transform::resize,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let base_path = "/mnt/c/Users/Formulatrix/Documents/Explorations/WebApplication1/tiles1705/";
|
||||
const SCALE: f64 = 0.01;
|
||||
const SIZE: u32 = 720;
|
||||
let actual_size = (SIZE as f64 * SCALE).trunc() as u32;
|
||||
|
||||
// Open the image (a PhotonImage is returned)
|
||||
let max_col = 31;
|
||||
let max_row = 55;
|
||||
let mut res = new_empty_image(actual_size * max_row, actual_size * max_col);
|
||||
for i in 1..=max_col {
|
||||
for j in 1..=max_row {
|
||||
let filename = format!("{}{}{}.png", base_path, number_to_column(i), j);
|
||||
// println!("{filename}");
|
||||
|
||||
let pre = open_image(filename).expect("File should open");
|
||||
let img = resize(
|
||||
&pre,
|
||||
actual_size,
|
||||
actual_size,
|
||||
photon_rs::transform::SamplingFilter::Nearest,
|
||||
);
|
||||
watermark(
|
||||
&mut res,
|
||||
&img,
|
||||
actual_size as i64 * j as i64,
|
||||
actual_size as i64 * i as i64,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply a sepia effect to the image.
|
||||
save_image(res, "raw_image.png").expect("File should be saved");
|
||||
}
|
||||
pub fn new_empty_image(width: u32, height: u32) -> PhotonImage {
|
||||
// 4 bytes per pixel (RGBA)
|
||||
let num_pixels = (width * height * 4) as usize;
|
||||
let raw_pixels = vec![0u8; num_pixels];
|
||||
PhotonImage::new(raw_pixels, width, height)
|
||||
}
|
||||
fn number_to_column(mut num: u32) -> String {
|
||||
let mut result = String::new();
|
||||
|
||||
while num > 0 {
|
||||
num -= 1;
|
||||
let ch = ((num % 26) as u8 + b'A') as char;
|
||||
result.insert(0, ch);
|
||||
num /= 26;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue