diff --git a/showbits-thermal-printer-ui/src/components/CDocumentXkcd.vue b/showbits-thermal-printer-ui/src/components/CDocumentXkcd.vue index 663dc22..564057f 100644 --- a/showbits-thermal-printer-ui/src/components/CDocumentXkcd.vue +++ b/showbits-thermal-printer-ui/src/components/CDocumentXkcd.vue @@ -7,12 +7,16 @@ const { disabled, error, makeRequest } = useApiRequest(); const form = useTemplateRef("form"); const number = ref(); +const dither = ref(true); +const bright = ref(false); const feed = ref(true); function submit() { const data = new URLSearchParams(); if (typeof number.value === "number") data.append("number", number.value.toFixed()); + data.append("dither", String(dither.value)); + data.append("bright", String(bright.value)); data.append("feed", String(feed.value)); void makeRequest("api/xkcd", data); } @@ -33,7 +37,18 @@ function submit() { /> - +
+ + + +
diff --git a/showbits-thermal-printer/src/documents/xkcd/data.json b/showbits-thermal-printer/src/documents/xkcd/data.json index 542acfb..0a931ec 100644 --- a/showbits-thermal-printer/src/documents/xkcd/data.json +++ b/showbits-thermal-printer/src/documents/xkcd/data.json @@ -2,5 +2,6 @@ "number": 3064, "title": "Lungfish", "alt": "I know having so many base pairs makes rebasing complicated, but you're in Bilateria, so shouldn't you at LEAST be better at using git head?", + "dither": false, "feed": false } diff --git a/showbits-thermal-printer/src/documents/xkcd/main.typ b/showbits-thermal-printer/src/documents/xkcd/main.typ index a19c15e..ee763ef 100644 --- a/showbits-thermal-printer/src/documents/xkcd/main.typ +++ b/showbits-thermal-printer/src/documents/xkcd/main.typ @@ -9,14 +9,18 @@ #text(size: 32pt, data.title) ] -// If the image is an odd number of pixels wide, we need to add an extra row of -// pixels (in this case, on the right) to ensure that the image pixels fall on -// screen pixels. -#context { - let img = image("image.png") - let width = measure(img).width - let additional = 2pt * calc.fract(width.pt() / 2) - align(center, stack(dir: ltr, img, h(additional))) +#if data.dither { + // If the image is an odd number of pixels wide, we need to add an extra row + // of pixels (in this case, on the right) to ensure that the image pixels fall + // on screen pixels. + context { + let img = image("image.png") + let width = measure(img).width + let additional = 2pt * calc.fract(width.pt() / 2) + align(center, stack(dir: ltr, img, h(additional))) + } +} else { + image("image.png", width: lib.width) } #align(center, data.alt) diff --git a/showbits-thermal-printer/src/documents/xkcd/mod.rs b/showbits-thermal-printer/src/documents/xkcd/mod.rs index 66f2cd8..cac5e86 100644 --- a/showbits-thermal-printer/src/documents/xkcd/mod.rs +++ b/showbits-thermal-printer/src/documents/xkcd/mod.rs @@ -24,12 +24,15 @@ struct Data { number: u32, title: String, alt: String, + dither: bool, feed: bool, } #[derive(Deserialize)] pub struct FormData { pub number: Option, + pub dither: Option, + pub bright: Option, pub feed: Option, } @@ -46,20 +49,29 @@ pub async fn post(server: State, Form(form): Form) -> somehow: let info = client.get(url).send().await?.json::().await?; let image_data = client.get(&info.img).send().await?.bytes().await?; - let image = image::load_from_memory(&image_data)?.into_rgba8(); - - let max_width = Some(384); - let max_height = Some(1024); - let image = super::image::dither(image, max_width, max_height, false, "stucki") - .map_err(somehow::Error)?; + let mut image = image::load_from_memory(&image_data)?.into_rgba8(); let data = Data { number: info.num, title: info.title, alt: info.alt, + dither: form.dither.unwrap_or(true), feed: form.feed.unwrap_or(true), }; + if data.dither { + let max_width = Some(384); + let max_height = Some(1024); + image = super::image::dither( + image, + max_width, + max_height, + form.bright.unwrap_or(false), + "stucki", + ) + .map_err(somehow::Error)?; + } + let mut bytes: Vec = Vec::new(); image .write_to(&mut Cursor::new(&mut bytes), ImageFormat::Png)