Sorting and better appearance
This commit is contained in:
parent
6a8c9c85be
commit
97eb0922e4
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
clap = { version = "4.5.16", features = ["derive"] }
|
||||
image = "0.25.2"
|
||||
palette = "0.7.6"
|
||||
|
||||
[profile.dev]
|
||||
debug = 0
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
<div class='color' style='background:##9D9998; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##9D9998
|
||||
</div> <div class='color' style='background:##7F6564; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##7F6564
|
||||
</div> <div class='color' style='background:##9FA4A8; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##9FA4A8
|
||||
</div> <div class='color' style='background:##81818D; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##81818D
|
||||
</div> <div class='color' style='background:##4A2A1B; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##4A2A1B
|
||||
</div> <div class='color' style='background:##96969C; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##96969C
|
||||
</div>
|
||||
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
47
src/main.rs
47
src/main.rs
|
|
@ -1,4 +1,5 @@
|
|||
use clap::{Parser, ValueEnum};
|
||||
use palette::{FromColor, Hsl, Srgb};
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -54,23 +55,61 @@ fn main() {
|
|||
// Iterate over the pixels
|
||||
for pixel in img.pixels() {
|
||||
// Get the color as a tuple (R, G, B, A)
|
||||
let rgba = pixel.2.to_rgb();
|
||||
let rgb = pixel.2.to_rgb();
|
||||
let srgb = Srgb::new(
|
||||
rgb[0] as f64 / 255.,
|
||||
rgb[1] as f64 / 255.,
|
||||
rgb[2] as f64 / 255.,
|
||||
);
|
||||
let hsl = Hsl::from_color(srgb);
|
||||
// Insert the color into the HashSet
|
||||
colors.insert((rgba[0], rgba[1], rgba[2]));
|
||||
colors.insert((
|
||||
rgb[0],
|
||||
rgb[1],
|
||||
rgb[2],
|
||||
(hsl.hue.into_positive_degrees() * 100.) as u32,
|
||||
));
|
||||
}
|
||||
|
||||
let mut vec = Vec::with_capacity(colors.len() + 1);
|
||||
// Print the unique colors
|
||||
for color in &colors {
|
||||
println!("Color: {:?}", color);
|
||||
|
||||
vec.push(format!("#{:02X}{:02X}{:02X}", color.0, color.1, color.2));
|
||||
}
|
||||
|
||||
println!("Found {} unique colors", colors.len());
|
||||
|
||||
let mut out = File::create(export_path).expect("Can't open output file");
|
||||
let mut out = File::create(&export_path).expect("Can't open output file");
|
||||
|
||||
write!(
|
||||
out,
|
||||
r#"<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>"#
|
||||
).unwrap();
|
||||
write!(out, "{:?}", &export_path.file_name()).unwrap();
|
||||
write!(
|
||||
out,
|
||||
r#"</title> <style> body{{background-color: #332f35;
|
||||
margin: 0; /* Remove default margin */
|
||||
padding: 0; /* Remove default padding */
|
||||
display: flex; /* Center content */
|
||||
justify-content: center; /* Center horizontally */
|
||||
align-items: center; /* Center vertically */
|
||||
height: 100vh; /* Make sure body takes up the full viewport height */
|
||||
}}
|
||||
.custom-div {{ display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-grow: 0;
|
||||
padding: 5px;
|
||||
background: #27232a;
|
||||
text-align: center;
|
||||
margin: 10px 0 20px;
|
||||
}} </style></head><body> <div class="custom-div"> "#
|
||||
)
|
||||
.unwrap();
|
||||
for v in vec {
|
||||
write!(out," <div class='color' style='background:#{}; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'> \n #{} \n</div>",v,v).expect("Can't write color in the output");
|
||||
write!(out," <div class='color' style='background:{}; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'> \n {} \n</div>",v,v).expect("Can't write color in the output");
|
||||
}
|
||||
write!(out, "</body></html>").unwrap();
|
||||
}
|
||||
|
|
|
|||
13
test.html
13
test.html
|
|
@ -1,13 +0,0 @@
|
|||
<div class='color' style='background:##9D9998; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##9D9998
|
||||
</div> <div class='color' style='background:##81818D; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##81818D
|
||||
</div> <div class='color' style='background:##4A2A1B; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##4A2A1B
|
||||
</div> <div class='color' style='background:##96969C; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##96969C
|
||||
</div> <div class='color' style='background:##9FA4A8; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##9FA4A8
|
||||
</div> <div class='color' style='background:##7F6564; color: #ffffff; min-width: 25%; height: 75px; line-height: 75px; font-size: 14px'>
|
||||
##7F6564
|
||||
</div>
|
||||
Reference in New Issue