Add more dithering options
This commit is contained in:
parent
618f298cc6
commit
c4c6887603
4 changed files with 47 additions and 15 deletions
|
|
@ -7,12 +7,16 @@ const { disabled, error, makeRequest } = useApiRequest();
|
|||
const form = useTemplateRef<HTMLFormElement>("form");
|
||||
|
||||
const number = ref<number>();
|
||||
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() {
|
|||
/>
|
||||
</label>
|
||||
|
||||
<label><input v-model="feed" type="checkbox" :disabled /> Feed</label>
|
||||
<div class="wide">
|
||||
<label><input v-model="dither" type="checkbox" :disabled /> Dither</label>
|
||||
<label
|
||||
><input
|
||||
v-model="bright"
|
||||
type="checkbox"
|
||||
:disabled="disabled || !dither"
|
||||
/>
|
||||
Bright</label
|
||||
>
|
||||
<label><input v-model="feed" type="checkbox" :disabled /> Feed</label>
|
||||
</div>
|
||||
|
||||
<button :disabled>Print</button>
|
||||
<CError :message="error" />
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -24,12 +24,15 @@ struct Data {
|
|||
number: u32,
|
||||
title: String,
|
||||
alt: String,
|
||||
dither: bool,
|
||||
feed: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormData {
|
||||
pub number: Option<u32>,
|
||||
pub dither: Option<bool>,
|
||||
pub bright: Option<bool>,
|
||||
pub feed: Option<bool>,
|
||||
}
|
||||
|
||||
|
|
@ -46,20 +49,29 @@ pub async fn post(server: State<Server>, Form(form): Form<FormData>) -> somehow:
|
|||
let info = client.get(url).send().await?.json::<ComicInfo>().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<u8> = Vec::new();
|
||||
image
|
||||
.write_to(&mut Cursor::new(&mut bytes), ImageFormat::Png)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue