Add rotate checkbox for image

This commit is contained in:
Joscha 2025-07-19 22:55:10 +02:00
parent 524670b7c9
commit b0f1828723
2 changed files with 13 additions and 1 deletions

View file

@ -10,6 +10,7 @@ const file = ref<File>();
const title = ref("");
const caption = ref("");
const algo = ref("stucki");
const rotate = ref(false);
const bright = ref(true);
const seamless = ref(false);
const feed = ref(true);
@ -33,6 +34,7 @@ function onFormSubmit() {
if (title.value) data.append("title", title.value);
if (caption.value) data.append("caption", caption.value);
data.append("algo", algo.value);
data.append("rotate", String(rotate.value));
data.append("bright", String(bright.value));
data.append("seamless", String(seamless.value));
data.append("feed", String(feed.value));
@ -89,6 +91,7 @@ function onImageChange() {
</label>
<div class="wide">
<label><input v-model="rotate" type="checkbox" :disabled /> Rotate</label>
<label><input v-model="bright" type="checkbox" :disabled /> Bright</label>
<label>
<input v-model="seamless" type="checkbox" :disabled />

View file

@ -91,6 +91,7 @@ struct Data {
pub async fn post(server: State<Server>, mut multipart: Multipart) -> somehow::Result<Response> {
let mut image = None;
let mut algo = "stucki".to_string();
let mut rotate = false;
let mut bright = true;
let mut data = Data {
@ -114,6 +115,9 @@ pub async fn post(server: State<Server>, mut multipart: Multipart) -> somehow::R
Some("algo") => {
algo = field.text().await?;
}
Some("rotate") => {
rotate = !field.text().await?.is_empty();
}
Some("bright") => {
bright = !field.text().await?.is_empty();
}
@ -139,7 +143,7 @@ pub async fn post(server: State<Server>, mut multipart: Multipart) -> somehow::R
}
// Decode image data
let image = {
let mut image = {
// https://github.com/image-rs/image/issues/2392#issuecomment-2547393362
let mut decoder = ImageReader::new(Cursor::new(image.as_bytes()))
.with_guessed_format()?
@ -150,6 +154,11 @@ pub async fn post(server: State<Server>, mut multipart: Multipart) -> somehow::R
decoded.to_rgba8()
};
// Rotate image
if rotate {
image = imageops::rotate90(&image);
}
// Dither image
let max_width = Some(384);
let max_height = Some(1024);