File size: 839 Bytes
16c48de
 
f75a524
16c48de
 
 
 
f75a524
16c48de
 
f75a524
 
 
 
 
 
 
 
 
 
 
 
16c48de
 
 
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
const express = require("express");
const multer = require("multer");
const { exec } = require("child_process");

const app = express();
const upload = multer({ storage: multer.memoryStorage() });

app.post("/convert", upload.single("image"), (req, res) => {
    if (!req.file) return res.status(400).send("No image uploaded");

    const width = req.query.width || 50;
    const command = `jp2a --width=${width} -`;

    const child = exec(command, { encoding: "utf8" });

    child.stdin.write(req.file.buffer);
    child.stdin.end();

    let ascii = "";
    child.stdout.on("data", (data) => (ascii += data));
    child.stdout.on("end", () => res.type("text/plain").send(ascii));
    child.stderr.on("data", () => res.status(500).send("Error processing image"));
});

app.listen(7860, () => console.log("Server running on port 7860"));