| 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")); |