Skip to content

Commit

Permalink
HTML support
Browse files Browse the repository at this point in the history
  • Loading branch information
madsravn committed Aug 1, 2023
1 parent 1b1bd22 commit 9958bad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use image::io::Reader;
use pixtra::canvas::Canvas;
use pixtra::utility::{count_colors, counted_colors_to_html};
use std::path::Path;

// TODO: Turn images grey
Expand All @@ -13,7 +14,10 @@ use std::path::Path;
// Inverse colors

fn main() {
let canvas = Canvas::new(4, 5);
let canvas = Canvas::load(&Path::new("testing.png")).unwrap();
let colors = count_colors(&canvas);
let output = counted_colors_to_html(&colors);
println!("{}", output);
canvas.save(Path::new("here.png")).expect("To be saved");
println!("Test");
}
Expand Down
8 changes: 8 additions & 0 deletions src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ pub fn count_colors(c: &Canvas) -> HashMap<Pixel, usize> {
map
}

pub fn counted_colors_to_html(map: &HashMap<Pixel, usize>) -> String {
let mut pairs: Vec<(Pixel, usize)> = map.iter().map(|(x, y)| (x.clone(), y.clone())).collect();
pairs.sort_by_key(|x| x.1);
pairs.reverse();
let output: String = pairs.iter().map(|x| format!("<tr> <td> {} </td> <td bgcolor=\"RGB({}, {}, {})\"> ({}, {}, {}) </td> </tr>", x.1, x.0.r, x.0.g, x.0.b, x.0.r, x.0.g, x.0.b).to_string()).collect();
output
}

pub fn diff(c1: &Canvas, c2: &Canvas) -> Canvas {
let c = Canvas::new(1, 1);
c
Expand Down

0 comments on commit 9958bad

Please sign in to comment.