Skip to content

Commit 731feaf

Browse files
committed
Adds edge cropping
1 parent 19afd65 commit 731feaf

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ pub mod checksum;
22
pub mod emblem;
33

44
extern crate chrono;
5+
extern crate image;
56

67

78
use chrono::*;
9+
use image::GenericImage;
810

911

1012
pub fn short_name(seconds: f64) -> String {
@@ -31,3 +33,13 @@ pub fn seconds_since_2000(now: chrono::datetime::DateTime<UTC>) -> f64 {
3133
None => panic!("No microseconds!")
3234
}
3335
}
36+
37+
pub fn crop_image(img: &mut image::DynamicImage) {
38+
for i in (0..64) {
39+
(*img).put_pixel( i, 0, image::Rgba([0u8, 0u8, 0u8, 0u8]));
40+
(*img).put_pixel( i, 63, image::Rgba([0u8, 0u8, 0u8, 0u8]));
41+
(*img).put_pixel( 0, i, image::Rgba([0u8, 0u8, 0u8, 0u8]));
42+
(*img).put_pixel(63, i, image::Rgba([0u8, 0u8, 0u8, 0u8]));
43+
}
44+
}
45+

src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fn main() {
2121
.help("Sets the input file to use")
2222
.required(true)
2323
.index(1))
24+
.arg(Arg::with_name("crop-edges")
25+
.short("c")
26+
.long("--crop-edges")
27+
.help("Crops the edges"))
2428
.arg(Arg::with_name("emblem-filename")
2529
.help("Specify a custom emblem filename to put in place of the default timestamp."))
2630
.subcommand(SubCommand::new("test")
@@ -47,9 +51,13 @@ fn main() {
4751
let short_name = image2emblem::short_name(seconds_since_2000);
4852
let full_name = image2emblem::full_name(&short_name);
4953

50-
let img64 = img.crop(0, 0, 64, 64);
54+
let mut img64 = img.crop(0, 0, 64, 64);
5155
let img32 = img64.resize(32, 32, image::FilterType::Lanczos3);
5256

57+
if matches.is_present("crop-edges") {
58+
image2emblem::crop_image(&mut img64);
59+
}
60+
5361
emblem.set_filename(short_name);
5462
emblem.set_timestamp(seconds_since_2000 as u32);
5563
let comment = format!("{} (Created using Rust awesomeness)", now.format("%y/%m/%d %H:%M"));

0 commit comments

Comments
 (0)