const fs = require('fs'); const cp = require('child_process'); const child_process = require("child_process"); const number = require('../../app.json')['signal']['raindrops']; let bottom = [ "jybgq", "auvwc", "mvaws", "wnujv" ]; let ponies = [...require('../../data/gdapd/members.json').filter(i => { return fs.existsSync("../../data/metadata/" + i.id + ".json") && !require("../../data/metadata/" + i.id + ".json").species.includes("human"); }), ...require('../../data/ynmuc/members.json').filter(i => { return fs.existsSync("../../data/metadata/" + i.id + ".json") && !require("../../data/metadata/" + i.id + ".json").species.includes("human"); })]; let columns = Math.ceil(Math.sqrt(ponies.length)); console.log(ponies.length + " ponies, so the image will contain " + columns + "x" + columns + " ponies"); let list = []; for (let pony of ponies) { if (list.includes(pony.name) || bottom.includes(pony.id)) continue; let metadata = require("../../data/metadata/" + pony.id + ".json"); let relations = [...(metadata.marefriends ?? []), ...(metadata.sisters ?? []), ...(metadata.caretakers ?? [])] list.push(pony.name); for (let relation of relations) { let relationPony = ponies.filter(i => i.id === relation.split("/")[1])[0] ?? null; if (relationPony) { if (!list.includes(relationPony.name) && !bottom.includes(pony.id)) list.push(relationPony.name); } } } for (let id of bottom) { let pony = ponies.filter(i => i.id === id)[0] ?? null; if (list.includes(pony.name)) continue; let metadata = require("../../data/metadata/" + pony.id + ".json"); let relations = [...(metadata.marefriends ?? []), ...(metadata.sisters ?? []), ...(metadata.caretakers ?? [])] list.push(pony.name); for (let relation of relations) { let relationPony = ponies.filter(i => i.id === relation.split("/")[1])[0] ?? null; if (relationPony) { if (!list.includes(relationPony.name)) list.push(relationPony.name); } } } let lines = []; while (list.length > 0) lines.push(list.splice(0, columns)); if (fs.existsSync("./output.png")) fs.unlinkSync("./output.png"); for (let index1 in lines) { process.stdout.write(index1 + ": "); index1 = parseInt(index1); let line = lines[index1]; let toRemove; for (let index2 in line) { index2 = parseInt(index2); let cell = line[index2]; let pony = ponies.filter(i => i.name === cell)[0] ?? null; process.stdout.write(pony.id); if (pony) { if (fs.existsSync("../../../assets/ponies/" + pony.id + ".png")) { if (!fs.existsSync("./" + index1 + ".png")) { cp.execFileSync("convert", ["../../../assets/ponies/" + pony.id + ".png", "-filter", "Point", "-resize", "x240", "./" + index1 + ".png"]); process.stdout.write("..."); toRemove = parseInt(cp.execFileSync("identify", ["-format", "%w", "./" + index1 + ".png"]).toString()) / 2; process.stdout.write("..."); } else { let width1 = (index2 + 1) * 240; let width2 = index2 * 120; cp.execFileSync("convert", ["../../../assets/ponies/" + pony.id + ".png", "-filter", "Point", "-resize", "x240", "./temp.png"]); process.stdout.write("."); cp.execFileSync("convert", ["-size", width1 + "x240", "xc:transparent", "canvas.png"]); process.stdout.write("."); cp.execFileSync("convert", ["canvas.png", "-colorspace", "sRGB", "./temp.png", "-geometry", "+" + width2 + "+0", "-composite", "./temp.png"]); process.stdout.write("."); cp.execFileSync("convert", ["./" + index1 + ".png", "-background", "none", "-extent", width1 + "x240", "./" + index1 + "-2.png"]); process.stdout.write("."); cp.execFileSync("convert", ["./" + index1 + "-2.png", "./temp.png", "-background", "none", "-flatten", "-trim", "+repage", "./" + index1 + "-3.png"]); process.stdout.write("."); fs.unlinkSync("./" + index1 + "-2.png"); fs.unlinkSync("./" + index1 + ".png"); fs.renameSync("./" + index1 + "-3.png", "./" + index1 + ".png"); process.stdout.write("."); } process.stdout.write(", "); } } } if (!fs.existsSync("./output.png")) { cp.execFileSync("convert", ["./" + index1 + ".png", "./output.png"]); process.stdout.write("...."); fs.unlinkSync("./" + index1 + ".png"); process.stdout.write("..."); } else { let height1 = (index1 + 1) * 480; let height2 = index1 * 120; cp.execFileSync("convert", ["./" + index1 + ".png", "-filter", "Point", "-resize", "x240", "./temp.png"]); process.stdout.write("."); cp.execFileSync("convert", ["-size", (columns * 240) + "x" + height1, "xc:transparent", "canvas.png"]); process.stdout.write("."); cp.execFileSync("convert", ["canvas.png", "-colorspace", "sRGB", "./temp.png", "-geometry", "+0+" + height2, "-composite", "./temp.png"]); process.stdout.write("."); cp.execFileSync("convert", ["./output.png", "-background", "none", "-extent", (columns * 240) + "x" + height1, "./output-2.png"]); process.stdout.write("."); cp.execFileSync("convert", ["./output-2.png", "./temp.png", "-background", "none", "-gravity", "Center", "-flatten", "-trim", "+repage", "./output-3.png"]); process.stdout.write("."); fs.unlinkSync("./output-2.png"); fs.unlinkSync("./output.png"); fs.unlinkSync("./temp.png"); fs.unlinkSync("./" + index1 + ".png"); fs.unlinkSync("./canvas.png"); process.stdout.write("."); fs.renameSync("./output-3.png", "./output.png"); process.stdout.write("."); } process.stdout.write("\n"); } process.stdout.write("."); let dimensions = cp.execFileSync("identify", ["-format", "%wx%h", "./output.png"]).toString(); process.stdout.write("."); let highest = Math.max(...dimensions.split("x").map(i => parseInt(i))) + 200; cp.execFileSync("convert", ["./output.png", "-background", "none", "-gravity", "Center", "-extent", highest + "x" + highest, "./output-2.png"]); process.stdout.write("."); cp.execFileSync("magick", ["-size", highest + "x" + highest, "-define", "gradient:direction=North", "gradient:#6acc28-#72ace5", "-colorspace", "sRGB", "gradient.png"]); process.stdout.write("."); cp.execFileSync("convert", ["./gradient.png", "./output-2.png", "-colorspace", "sRGB", "-flatten", "./output.png"]); process.stdout.write("."); fs.unlinkSync("gradient.png"); fs.unlinkSync("output-2.png"); process.stdout.write("."); child_process.execFileSync("signal-cli", [ "-a", number, "updateGroup", "--group", "Im1iOlG3TxtiwAad+aVPJ6RsdSN3YCQauz1SmYiMqA8=", "--avatar", __dirname + "/output.png" ]); process.stdout.write("."); child_process.execFileSync("signal-cli", [ "-a", number, "sendSyncRequest" ]); process.stdout.write("."); console.log("\nComplete!");