Add rotate checkbox for xkcd

This commit is contained in:
Joscha 2025-09-02 20:16:43 +02:00
parent b0f1828723
commit 2f9472b803
2 changed files with 9 additions and 1 deletions

View file

@ -7,6 +7,7 @@ const { disabled, error, makeRequest } = useApiRequest();
const form = useTemplateRef<HTMLFormElement>("form");
const number = ref<number>();
const rotate = ref(false);
const dither = ref(true);
const bright = ref(true);
const feed = ref(true);
@ -15,6 +16,7 @@ function submit() {
const data = new URLSearchParams();
if (typeof number.value === "number")
data.append("number", number.value.toFixed());
data.append("rotate", String(rotate.value));
data.append("dither", String(dither.value));
data.append("bright", String(bright.value));
data.append("feed", String(feed.value));
@ -38,6 +40,7 @@ function submit() {
</label>
<div class="wide">
<label><input v-model="rotate" type="checkbox" :disabled /> Rotate</label>
<label><input v-model="dither" type="checkbox" :disabled /> Dither</label>
<label
><input

View file

@ -6,7 +6,7 @@ use axum::{
extract::State,
response::{IntoResponse, Response},
};
use image::ImageFormat;
use image::{ImageFormat, imageops};
use serde::{Deserialize, Serialize};
use crate::server::{Server, somehow};
@ -31,6 +31,7 @@ struct Data {
#[derive(Deserialize)]
pub struct FormData {
pub number: Option<u32>,
pub rotate: Option<bool>,
pub dither: Option<bool>,
pub bright: Option<bool>,
pub feed: Option<bool>,
@ -59,6 +60,10 @@ pub async fn post(server: State<Server>, Form(form): Form<FormData>) -> somehow:
feed: form.feed.unwrap_or(true),
};
if form.rotate.unwrap_or(false) {
image = imageops::rotate90(&image);
}
if data.dither {
let max_width = Some(384);
let max_height = Some(1024);