-
Notifications
You must be signed in to change notification settings - Fork 1
/
sixel.ts
executable file
·54 lines (44 loc) · 1.84 KB
/
sixel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env -S deno run -A
import { fromPng } from "npm:@rgba-image/png";
import * as sixel from "npm:sixel";
import { stringToU8a } from "https://deno.land/x/[email protected]/util/mod.ts";
import {
ImageMagick,
initializeImageMagick,
MagickGeometry,
} from "https://deno.land/x/[email protected]/mod.ts";
await initializeImageMagick();
async function image2sixel(imageBuffer: Uint8Array): Uint8Array {
let resizedBuffer = await new Promise<Uint8Array>((resolve) => {
ImageMagick.read(imageBuffer, (image) => {
// console.log(image.width, image.height);
let scaleFactor = 160.0 / image.height;
const sizingData = new MagickGeometry(
image.width * scaleFactor,
image.height * scaleFactor,
);
image.resize(sizingData);
image.write((data) => resolve(data));
});
});
let s = await fromPng(resizedBuffer);
return stringToU8a(sixel.image2sixel(s.data, s.width, s.height));
}
let img = await fetch(
"https://raw.githubusercontent.com/subdirectory/subshell/main/.github/SubshellBanner.png",
);
let imageBuffer = new Uint8Array(await img.arrayBuffer());
Deno.stdout.writeSync(await image2sixel(imageBuffer));
img = await fetch(
"https://raw.githubusercontent.com/subdirectory/subshell/main/.github/GearShellBanner.png",
);
imageBuffer = new Uint8Array(await img.arrayBuffer());
Deno.stdout.writeSync(await image2sixel(imageBuffer));
// imageBuffer = Deno.readFileSync("./GearShell_vectorized.png");
// Deno.stdout.writeSync(await image2sixel(imageBuffer));
// Deno.stdout.writeSync(await image2sixel(Deno.readFileSync("./.github/SubshellBanner.png")));
// TODO: investigate: this line must be executed before the next line succeeds
await image2sixel(Deno.readFileSync("./.github/SubshellBanner.png"));
Deno.stdout.writeSync(
await image2sixel(Deno.readFileSync("./.github/GearShellBanner.png")),
);