andreterron-pngtest.web.val.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Buffer } from "node:buffer";
export async function pngTest(req: Request): Promise<Response> {
var { default: pnglib } = await import("npm:pnglib");
const w = 64;
const h = 32;
var p = new pnglib(w, h, 8); // width,height,depth
p.color(0, 0, 0, 0); // First color: background (red, green, blue, alpha)
p.color(255, 0, 0, 255); // Second color: paint (red, green, blue, alpha)
for (let y = 0; y < h; y += 2) {
for (let x = 0; x < w; x += 2) {
let index = p.index(x, y);
p.buffer[index] = "\x01";
}
}
var img = p.getBase64();
var imgbase64 = new Buffer(img, "base64");
return new Response(imgbase64, {
headers: {
"Content-Type": "image/png",
},
status: 200,
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
September 4, 2024