2019-10-16 19:47:53 -03:00
|
|
|
const request = require('request')
|
|
|
|
const Jimp = require('jimp');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2019-10-20 16:21:16 -03:00
|
|
|
const icons = require('../icons/gameSheet.json');
|
|
|
|
const colors = require('../misc/colors.json');
|
2019-10-21 00:33:01 -03:00
|
|
|
const forms = require('../icons/forms.json')
|
2020-06-22 21:58:33 -04:00
|
|
|
const offsets = require('../icons/offsets.json');
|
2019-10-21 00:33:01 -03:00
|
|
|
|
2019-10-20 16:21:16 -03:00
|
|
|
function recolor(img, col) {
|
|
|
|
return img.scan(0, 0, img.bitmap.width, img.bitmap.height, function (x, y, idx) {
|
|
|
|
if (img.bitmap.data.slice(idx, idx+3).every(function(val) {return val >= 20 && val <= 255})) { // If it's not "black, i.e. we want to recolor it"
|
|
|
|
this.bitmap.data[idx] = colors[col].r / (255 / this.bitmap.data[idx]);
|
|
|
|
this.bitmap.data[idx + 1] = colors[col].g / (255 / this.bitmap.data[idx + 1]);
|
|
|
|
this.bitmap.data[idx + 2] = colors[col].b / (255 / this.bitmap.data[idx + 2]);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-03-26 15:17:40 -03:00
|
|
|
|
2020-06-20 15:49:10 -04:00
|
|
|
/* Caveat of genFileName is that if there are any falsey values in the arguments they are ignored.
|
|
|
|
This is usually a good thing though - avoid issues by not putting something like 0 instead of '0' */
|
2020-06-22 21:58:33 -04:00
|
|
|
function genFileName(...args) { return args.filter(function(val) {return val}).join('_') +'_001.png' }
|
2020-06-20 15:49:10 -04:00
|
|
|
function fromIcons(filename) { return `./icons/${filename}` }
|
2019-10-17 09:26:08 -03:00
|
|
|
let cache = {};
|
2019-10-21 00:33:01 -03:00
|
|
|
|
2019-10-16 19:47:53 -03:00
|
|
|
module.exports = async (app, req, res) => {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2019-11-14 01:55:09 -03:00
|
|
|
function buildIcon(account) {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2019-11-14 01:55:09 -03:00
|
|
|
if (!account) account = []
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2019-10-21 00:33:01 -03:00
|
|
|
let { form, ind } = forms[req.query.form] || {};
|
2019-10-20 16:21:16 -03:00
|
|
|
form = form || 'player';
|
|
|
|
ind = ind || 21;
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2019-10-20 16:21:16 -03:00
|
|
|
let iconID = req.query.icon || account[ind] || 1;
|
2020-03-31 15:50:40 -03:00
|
|
|
let col1 = req.query.col1 || account[10] || 0;
|
2019-10-20 16:21:16 -03:00
|
|
|
let col2 = req.query.col2 || account[11] || 3;
|
|
|
|
let outline = req.query.glow || account[28] || "0";
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2020-06-20 15:49:10 -04:00
|
|
|
// meant for debugging robot/spider offsets, but i'll leave it in anyways
|
|
|
|
let glowOffset = (req.query.off || "").split(",").map(x => Number(x))
|
|
|
|
if (!glowOffset.some(x => x != 0)) glowOffset = []
|
|
|
|
|
2020-06-22 21:58:33 -04:00
|
|
|
let topless = form == "bird" && req.query.topless
|
2020-09-22 19:37:21 -03:00
|
|
|
let autoSize = req.query.size == "auto"
|
|
|
|
let sizeParam = autoSize || (req.query.size && !isNaN(req.query.size))
|
2019-10-15 23:42:47 -03:00
|
|
|
if (outline == "0") outline = false;
|
|
|
|
|
2019-10-20 16:21:16 -03:00
|
|
|
if (iconID && iconID.toString().length == 1) iconID = "0" + iconID;
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2019-10-20 16:21:16 -03:00
|
|
|
if (col1 == 15) outline = true;
|
|
|
|
function genImageName(...args) {
|
|
|
|
return genFileName(form, iconID, ...args);
|
|
|
|
}
|
|
|
|
let icon, glow, extra;
|
|
|
|
function setBaseIcons() {
|
|
|
|
icon = genImageName(isSpecial && '01');
|
|
|
|
glow = genImageName(isSpecial && '01', '2');
|
|
|
|
extra = genImageName(isSpecial && '01', 'extra');
|
|
|
|
}
|
|
|
|
const isSpecial = ['robot', 'spider'].includes(form);
|
|
|
|
setBaseIcons();
|
|
|
|
|
|
|
|
if (!fs.existsSync(fromIcons(icon)) || (isSpecial && !fs.existsSync(fromIcons(genImageName('02'))))) {
|
|
|
|
iconID = '01';
|
|
|
|
setBaseIcons();
|
|
|
|
// Condition on next line should never be satisfied but you never know!
|
|
|
|
if (!fs.existsSync(fromIcons(icon))) return res.sendFile(path.join(__dirname, '../assets/unknownIcon.png'))
|
2019-10-15 23:42:47 -03:00
|
|
|
}
|
|
|
|
|
2020-09-22 19:37:21 -03:00
|
|
|
let ex = fromIcons(extra)
|
|
|
|
let hasExtra = fs.existsSync(ex)
|
|
|
|
|
2020-03-31 15:46:40 -03:00
|
|
|
if (!colors[col1]) col1 = 0
|
2019-10-15 23:42:47 -03:00
|
|
|
if (!colors[col2]) col2 = 3
|
|
|
|
|
2020-09-22 19:37:21 -03:00
|
|
|
let col3 = req.query.col3
|
|
|
|
if (col3 && (!hasExtra || !colors[col3] || col3 == "12")) col3 = null
|
|
|
|
|
|
|
|
let iconCode = `${req.query.form == "cursed" ? "cursed" : form}${topless ? "top" : ""}-${iconID}-${col1}-${col2}-${col3 || "x"}-${outline ? 1 : 0}`
|
|
|
|
|
2020-06-20 15:49:10 -04:00
|
|
|
if (!sizeParam && !glowOffset.length && cache[iconCode]) {
|
2019-10-17 09:26:08 -03:00
|
|
|
clearTimeout(cache[iconCode].timeoutID);
|
2020-09-22 19:37:21 -03:00
|
|
|
cache[iconCode].timeoutID = setTimeout(function() {delete cache[iconCode]}, 1800000);
|
2019-10-17 09:26:08 -03:00
|
|
|
return res.end(cache[iconCode].value);
|
|
|
|
}
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
let useExtra = false
|
|
|
|
|
2019-10-20 16:21:16 -03:00
|
|
|
let originalOffset = icons[icon].spriteOffset;
|
2020-06-20 15:49:10 -04:00
|
|
|
let minusOrigOffset = function(x, y) { return x - originalOffset[y] }
|
2019-10-20 16:21:16 -03:00
|
|
|
let offset = icons[glow].spriteOffset.map(minusOrigOffset);
|
|
|
|
let robotLeg1, robotLeg2, robotLeg3, robotLeg3b, robotLeg2b, robotLeg1b, robotLeg1c;
|
|
|
|
let robotOffset1, robotOffset2, robotOffset3, robotOffset1b, robotOffset2b, robotOffset3b;
|
2020-06-22 21:58:33 -04:00
|
|
|
let robotGlow1, robotGlow2, robotGlow3
|
|
|
|
let ufoTop, ufoOffset, ufoCoords, ufoSprite
|
2020-09-22 19:37:21 -03:00
|
|
|
let extrabit, offset2, size2;
|
2020-06-20 15:49:10 -04:00
|
|
|
|
2019-10-20 16:21:16 -03:00
|
|
|
if (isSpecial) {
|
|
|
|
const legs = [1,2,3].map(function(val) {return genImageName(`0${val+1}`)});
|
|
|
|
const glows = [1,2,3].map(function(val) {return genImageName(`0${val+1}`, '2')});
|
|
|
|
robotOffset1 = icons[legs[0]].spriteOffset.map(minusOrigOffset).concat(icons[legs[0]].spriteSize);
|
|
|
|
robotOffset2 = icons[legs[1]].spriteOffset.map(minusOrigOffset).concat(icons[legs[1]].spriteSize);
|
|
|
|
robotOffset3 = icons[legs[2]].spriteOffset.map(minusOrigOffset).concat(icons[legs[2]].spriteSize);
|
|
|
|
|
|
|
|
robotOffset1b = icons[glows[0]].spriteOffset.map(minusOrigOffset).concat(icons[glows[0]].spriteSize);
|
|
|
|
robotOffset2b = icons[glows[1]].spriteOffset.map(minusOrigOffset).concat(icons[glows[1]].spriteSize);
|
|
|
|
robotOffset3b = icons[glows[2]].spriteOffset.map(minusOrigOffset).concat(icons[glows[2]].spriteSize);
|
|
|
|
|
|
|
|
robotLeg1 = new Jimp(fromIcons(legs[0])); robotGlow1 = new Jimp(fromIcons(glows[0]))
|
|
|
|
robotLeg2 = new Jimp(fromIcons(legs[1])); robotGlow2 = new Jimp(fromIcons(glows[1]))
|
|
|
|
robotLeg3 = new Jimp(fromIcons(legs[2])); robotGlow3 = new Jimp(fromIcons(glows[2]))
|
2020-06-20 15:49:10 -04:00
|
|
|
|
|
|
|
if (!glowOffset.length) glowOffset = offsets[form][+iconID] || []
|
2019-10-15 23:42:47 -03:00
|
|
|
}
|
|
|
|
|
2019-10-20 16:21:16 -03:00
|
|
|
Jimp.read(fromIcons(glow)).then(async function (image) {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
let size = [image.bitmap.width, image.bitmap.height]
|
|
|
|
let glow = recolor(image, col2)
|
2019-10-20 16:21:16 -03:00
|
|
|
let imgOff = isSpecial ? 100 : 0
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2020-09-22 19:37:21 -03:00
|
|
|
let eb = fromIcons(extra)
|
|
|
|
if (fs.existsSync(eb)) {
|
|
|
|
extrabit = icons[extra]
|
|
|
|
offset2 = extrabit.spriteOffset.map(minusOrigOffset);
|
|
|
|
size2 = extrabit.spriteSize;
|
|
|
|
extra = new Jimp(eb);
|
|
|
|
if (col3) await Jimp.read(eb).then(e => { extra = recolor(e, col3) })
|
|
|
|
useExtra = true
|
|
|
|
}
|
|
|
|
|
2019-10-20 16:21:16 -03:00
|
|
|
Jimp.read(fromIcons(icon)).then(async function (ic) {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
let iconSize = [ic.bitmap.width, ic.bitmap.height]
|
|
|
|
recolor(ic, col1)
|
|
|
|
ic.composite(glow, (iconSize[0] / 2) - (size[0] / 2) + offset[0], (iconSize[1] / 2) - (size[1] / 2) - offset[1], { mode: Jimp.BLEND_DESTINATION_OVER })
|
|
|
|
|
2020-06-22 21:58:33 -04:00
|
|
|
if (form == "bird" && !topless) {
|
|
|
|
ufoTop = genImageName('3')
|
|
|
|
ufoOffset = icons[ufoTop].spriteOffset.map(minusOrigOffset).concat(icons[ufoTop].spriteSize);
|
|
|
|
ufoCoords = [imgOff + (iconSize[0] / 2) - (ufoOffset[2] / 2) + ufoOffset[0], (iconSize[1] / 2) - (ufoOffset[3] / 2) - ufoOffset[1] + 300 - iconSize[1]]
|
|
|
|
ufoSprite = fromIcons(ufoTop)
|
|
|
|
ic.contain(iconSize[0], 300, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_BOTTOM)
|
|
|
|
// Only add dome if there's no glow, otherwise the dome will be outlined as well
|
|
|
|
if (!outline) ic.composite(await Jimp.read(ufoSprite), ufoCoords[0], ufoCoords[1], {mode: Jimp.BLEND_DESTINATION_OVER})
|
2019-10-15 23:42:47 -03:00
|
|
|
}
|
|
|
|
|
2019-11-05 23:59:56 -03:00
|
|
|
if (form == "robot" || req.query.form == "cursed") {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
ic.contain(iconSize[0], 300, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_TOP)
|
|
|
|
ic.contain(iconSize[0] + 200, 300, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_TOP)
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotGlow1)).then(rob => {
|
|
|
|
rob.rotate(-45)
|
|
|
|
robotGlow1 = recolor(rob, col2)
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotGlow2)).then(rob => {
|
|
|
|
rob.rotate(45)
|
|
|
|
robotGlow2 = recolor(rob, col2)
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotGlow3)).then(rob => {
|
|
|
|
robotGlow3 = recolor(rob, col2)
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg1)).then(rob => {
|
|
|
|
rob.rotate(-45)
|
|
|
|
recolor(rob, col1)
|
2020-06-20 15:49:10 -04:00
|
|
|
rob.composite(robotGlow1, (robotOffset1[2] - robotOffset1b[2]) + (glowOffset[0] || 1), ((robotOffset1[3] - robotOffset1b[3]) / 2) + (glowOffset[1] || 0), { mode: Jimp.BLEND_DESTINATION_OVER })
|
2019-10-15 23:42:47 -03:00
|
|
|
robotLeg1 = rob
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg2)).then(rob => {
|
|
|
|
rob.rotate(45)
|
|
|
|
recolor(rob, col1)
|
2020-06-20 15:49:10 -04:00
|
|
|
rob.composite(robotGlow2, ((robotOffset2[2] - robotOffset2b[2]) / 4) + (glowOffset[4] || 0), ((robotOffset2[3] - robotOffset2b[3]) / 2) + (glowOffset[5] || 0), { mode: Jimp.BLEND_DESTINATION_OVER })
|
2019-10-15 23:42:47 -03:00
|
|
|
robotLeg2 = rob
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg2)).then(rob => {
|
|
|
|
robotLeg2b = rob.color([{ apply: 'darken', params: [20] }]).rotate(-5)
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg3)).then(rob => {
|
|
|
|
recolor(rob, col1)
|
2020-06-20 15:49:10 -04:00
|
|
|
rob.composite(robotGlow3, ((robotOffset3[2] - robotOffset3b[2]) / 2) + (glowOffset[2] || 0), ((robotOffset3[3] - robotOffset3b[3]) / 2) + (glowOffset[3] || 0), { mode: Jimp.BLEND_DESTINATION_OVER })
|
2019-10-15 23:42:47 -03:00
|
|
|
robotLeg3 = rob
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg3)).then(rob => {
|
|
|
|
robotLeg3b = rob.color([{ apply: 'darken', params: [10] }])
|
|
|
|
})
|
|
|
|
|
|
|
|
ic.composite(robotLeg2b, 100 + (iconSize[0] / 2) - (robotOffset2[2]) + robotOffset2[0] - 31, (iconSize[1] / 2) - (robotOffset2[3]) - robotOffset2[1] + 73)
|
|
|
|
ic.composite(robotLeg3b, 100 + (iconSize[0] / 2) - (robotOffset3[2]) + robotOffset3[0] + 20, (iconSize[1] / 2) - (robotOffset3[3]) - robotOffset3[1] + 78)
|
|
|
|
ic.composite(robotLeg2, 100 + (iconSize[0] / 2) - (robotOffset2[2]) + robotOffset2[0] - 20, (iconSize[1] / 2) - (robotOffset2[3]) - robotOffset2[1] + 73)
|
|
|
|
ic.composite(robotLeg3, 100 + (iconSize[0] / 2) - (robotOffset3[2]) + robotOffset3[0] + 40, (iconSize[1] / 2) - (robotOffset3[3]) - robotOffset3[1] + 78)
|
|
|
|
ic.composite(robotLeg1, 100 + (iconSize[0] / 2) - (robotOffset1[2]) + robotOffset1[0] - 20, (iconSize[1] / 2) - (robotOffset1[3]) - robotOffset1[1] + 50)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-05 23:59:56 -03:00
|
|
|
else if (form == "spider") {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
let spiderBody;
|
|
|
|
ic.contain(iconSize[0], 300, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_TOP)
|
|
|
|
ic.contain(iconSize[0] + 200, 300, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_TOP)
|
|
|
|
|
|
|
|
if (iconID == "07") {
|
|
|
|
robotOffset2[2] -= 10
|
|
|
|
robotOffset2[1] += 12
|
|
|
|
robotOffset1b[3] -= 105
|
|
|
|
robotOffset2b[3] -= 150
|
|
|
|
robotOffset2b[2] -= 60
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iconID == "16") {
|
|
|
|
robotOffset1b[3] -= 100
|
|
|
|
robotOffset2b[3] -= 200
|
|
|
|
robotOffset2b[2] -= 30
|
|
|
|
}
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotGlow1)).then(rob => {
|
|
|
|
if (robotGlow1.bitmap.width < 10) robotGlow1.opacity(0)
|
|
|
|
else robotGlow1 = recolor(rob, col2)
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotGlow2)).then(rob => {
|
|
|
|
robotGlow2 = recolor(rob, col2)
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotGlow3)).then(rob => {
|
|
|
|
robotGlow3 = recolor(rob, col2)
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg1)).then(rob => {
|
|
|
|
recolor(rob, col1)
|
2020-06-20 15:49:10 -04:00
|
|
|
rob.composite(robotGlow1, ((robotOffset1[2] - robotOffset1b[2]) / 2) + (glowOffset[2] || 0), ((robotOffset1[3] - robotOffset1b[3]) / 4) + (glowOffset[3] || 0), { mode: Jimp.BLEND_DESTINATION_OVER })
|
2019-10-15 23:42:47 -03:00
|
|
|
robotLeg1 = rob
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg2)).then(rob => {
|
|
|
|
recolor(rob, col1)
|
2020-06-20 15:49:10 -04:00
|
|
|
rob.composite(robotGlow2, ((robotOffset2[2] - robotOffset2b[2]) / 6) + (glowOffset[0] || 0), ((robotOffset2[3] - robotOffset2b[3]) / 6) + (glowOffset[1] || 0), { mode: Jimp.BLEND_DESTINATION_OVER })
|
2019-10-15 23:42:47 -03:00
|
|
|
rob.rotate(-40)
|
|
|
|
robotLeg2 = rob
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg1)).then(rob => {
|
|
|
|
robotLeg1b = rob.color([{ apply: 'darken', params: [20] }])
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg1b)).then(rob => {
|
|
|
|
robotLeg1c = rob.mirror(true, false)
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(robotLeg3)).then(rob => {
|
|
|
|
recolor(rob, col1)
|
2020-06-20 15:49:10 -04:00
|
|
|
rob.composite(robotGlow3, ((robotOffset3[2] - robotOffset3b[2]) / 2) + (glowOffset[4] || 0), ((robotOffset3[3] - robotOffset3b[3]) / 2) + (glowOffset[5] || 0), { mode: Jimp.BLEND_DESTINATION_OVER })
|
2019-10-15 23:42:47 -03:00
|
|
|
robotLeg3 = rob
|
|
|
|
})
|
|
|
|
|
|
|
|
await Jimp.read(new Jimp(ic)).then(rob => {
|
|
|
|
spiderBody = rob
|
|
|
|
})
|
|
|
|
|
|
|
|
ic.composite(robotLeg3, 100 + (iconSize[0] / 2) - (robotOffset3[2]) + (robotOffset3[0]), (iconSize[1] / 2) - (robotOffset2[3]) - robotOffset2[1] + 77)
|
|
|
|
ic.composite(robotLeg1b, 100 + (iconSize[0] / 2) - (robotOffset1[2]) + robotOffset1[0] + 35, (iconSize[1] / 2) - (robotOffset1[3]) - robotOffset1[1] + 70)
|
|
|
|
ic.composite(robotLeg1c, 100 + (iconSize[0] / 2) - (robotOffset1[2]) + robotOffset1[0] + 75, (iconSize[1] / 2) - (robotOffset1[3]) - robotOffset1[1] + 70)
|
|
|
|
// ^ BELOW
|
|
|
|
ic.composite(spiderBody, 0, 0)
|
|
|
|
// v ABOVE
|
|
|
|
ic.composite(robotLeg2, 100 + (iconSize[0] / 2) - (robotOffset2[2]) + robotOffset2[0] - 60, (iconSize[1] / 2) - (robotOffset2[3]) - robotOffset2[1] + 75)
|
|
|
|
ic.composite(robotLeg1, 100 + (iconSize[0] / 2) - (robotOffset1[2]) + robotOffset1[0] + 7, (iconSize[1] / 2) - (robotOffset1[3]) - robotOffset1[1] + 70)
|
|
|
|
}
|
|
|
|
|
2020-06-22 22:07:13 -04:00
|
|
|
if (useExtra) ic.composite(extra, imgOff + (iconSize[0] / 2) - (size2[0] / 2) + offset2[0], (iconSize[1] / 2) - (size2[1] / 2) - offset2[1] + (form == "bird" && !req.query.topless ? 300 - iconSize[1] : 0))
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
let finalSize = [ic.bitmap.width, ic.bitmap.height]
|
|
|
|
|
2020-06-22 21:58:33 -04:00
|
|
|
function finish(img) {
|
|
|
|
img.autocrop(0.01, false)
|
2020-06-24 18:26:53 -04:00
|
|
|
if (form == "swing") img.resize(120, 111)
|
2020-06-22 21:58:33 -04:00
|
|
|
if (img.bitmap.height == 300) ic.autocrop(1, false)
|
|
|
|
if (sizeParam) {
|
2020-09-22 19:37:21 -03:00
|
|
|
let thicc = img.bitmap.width > img.bitmap.height
|
|
|
|
let imgSize = req.query.size == "auto" ? (thicc ? img.bitmap.width : img.bitmap.height) : Math.round(req.query.size)
|
2020-06-22 21:58:33 -04:00
|
|
|
if (imgSize < 32) imgSize = 32
|
|
|
|
if (imgSize > 512) imgSize = 512
|
2020-09-22 19:37:21 -03:00
|
|
|
if (thicc) img.contain(img.bitmap.width, img.bitmap.width, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE)
|
|
|
|
else img.contain(img.bitmap.height, img.bitmap.height, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE)
|
2020-06-22 21:58:33 -04:00
|
|
|
img.resize(imgSize, Jimp.AUTO)
|
|
|
|
}
|
|
|
|
img.getBuffer(Jimp.AUTO, (err, buffer) => {
|
2020-06-21 00:21:14 -04:00
|
|
|
if (!sizeParam && !glowOffset.length) {
|
2020-03-26 15:17:40 -03:00
|
|
|
cache[iconCode] = {
|
2020-06-22 21:58:33 -04:00
|
|
|
value: buffer,
|
2020-09-22 19:37:21 -03:00
|
|
|
timeoutID: setTimeout(function() {delete cache[iconCode]}, 1800000)
|
2020-03-26 15:17:40 -03:00
|
|
|
}
|
2019-10-17 09:26:08 -03:00
|
|
|
}
|
2020-06-22 21:58:33 -04:00
|
|
|
return res.end(buffer, 'base64')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!outline) return finish(ic)
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2020-06-22 21:58:33 -04:00
|
|
|
else {
|
|
|
|
|
|
|
|
ic.getBuffer(Jimp.AUTO, function (err, buff) {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
const Canvas = require('canvas')
|
|
|
|
, Image = Canvas.Image
|
|
|
|
, canvas = Canvas.createCanvas(finalSize[0] + 10, finalSize[1] + 10)
|
|
|
|
, ctx = canvas.getContext('2d');
|
|
|
|
|
|
|
|
if (col2 == 15) col2 = col1;
|
|
|
|
if (col1 == 15 && col2 == 15) col2 = 12;
|
|
|
|
|
|
|
|
const img = new Image()
|
|
|
|
img.onload = () => {
|
|
|
|
var dArr = [-1, -1, 0, -1, 1, -1, -1, 0, 1, 0, -1, 1, 0, 1, 1, 1], // offset array
|
|
|
|
s = 2, i = 0, x = canvas.width / 2 - finalSize[0] / 2, y = canvas.height / 2 - finalSize[1] / 2;
|
|
|
|
|
2020-03-26 15:17:40 -03:00
|
|
|
for (; i < dArr.length; i += 2) ctx.drawImage(img, x + dArr[i] * s, y + dArr[i + 1] * s);
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
ctx.globalCompositeOperation = "source-in";
|
|
|
|
ctx.fillStyle = `rgba(${colors[col2].r}, ${colors[col2].g}, ${colors[col2].b}, 1})`;
|
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
ctx.globalCompositeOperation = "source-over";
|
|
|
|
ctx.imageSmoothingEnabled = false;
|
2020-03-26 15:17:40 -03:00
|
|
|
|
2020-06-22 21:58:33 -04:00
|
|
|
// Add UFO top last so it doesn't get glow'd
|
|
|
|
if (form == "bird" && !topless) {
|
|
|
|
const dome = new Image()
|
|
|
|
dome.src = ufoSprite
|
|
|
|
ctx.drawImage(dome, ufoCoords[0]+5, ufoCoords[1]+5)
|
|
|
|
}
|
|
|
|
|
2019-10-15 23:42:47 -03:00
|
|
|
ctx.drawImage(img, x, y)
|
2020-03-26 15:17:40 -03:00
|
|
|
|
2019-10-15 23:42:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
img.onerror = err => { throw err }
|
2020-06-22 21:58:33 -04:00
|
|
|
img.src = buff
|
2020-03-26 15:17:40 -03:00
|
|
|
|
2020-06-22 21:58:33 -04:00
|
|
|
Jimp.read(canvas.toBuffer()).then(b => {
|
|
|
|
return finish(b)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2019-10-15 23:42:47 -03:00
|
|
|
})
|
|
|
|
})
|
2019-11-14 01:55:09 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
let username = req.params.text
|
|
|
|
let result = []
|
|
|
|
|
2020-09-10 10:02:40 -03:00
|
|
|
if (app.offline || req.query.hasOwnProperty("noUser") || req.query.hasOwnProperty("nouser") || username == "icon") return buildIcon()
|
2020-09-22 19:37:21 -03:00
|
|
|
res.contentType('image/png');
|
2019-11-14 01:55:09 -03:00
|
|
|
|
2020-11-01 17:29:32 -03:00
|
|
|
request.post(app.endpoint + 'getGJUsers20.php', req.gdParams({ str: username }), function (err1, res1, body1) {
|
2019-11-14 01:55:09 -03:00
|
|
|
if (err1 || !body1 || body1 == "-1") return buildIcon()
|
|
|
|
else result = app.parseResponse(body1);
|
|
|
|
|
2020-11-01 17:29:32 -03:00
|
|
|
request.post(app.endpoint + 'getGJUserInfo20.php', req.gdParams({ targetAccountID: result[16] }), function (err2, res2, body2) {
|
2019-11-14 01:55:09 -03:00
|
|
|
|
|
|
|
if (!err2 && body2 && body2 != '-1') return buildIcon(app.parseResponse(body2));
|
|
|
|
else return buildIcon()
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2019-10-17 09:26:08 -03:00
|
|
|
}
|