From 0456a0e74131cfd00f3e4456be479b149b919405 Mon Sep 17 00:00:00 2001 From: Colon <56617416+GDColon@users.noreply.github.com> Date: Sat, 20 Jun 2020 15:49:10 -0400 Subject: [PATCH 1/5] Fixed broken robots/spiders with the power of hardcoding --- api/icon.js | 46 ++++++++++++++++++++++------------------------ icons/offsets.json | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 icons/offsets.json diff --git a/api/icon.js b/api/icon.js index 34e43c1..43da891 100644 --- a/api/icon.js +++ b/api/icon.js @@ -5,6 +5,7 @@ const path = require('path'); const icons = require('../icons/gameSheet.json'); const colors = require('../misc/colors.json'); const forms = require('../icons/forms.json') +const offsets = require('../icons/offsets.json') function recolor(img, col) { return img.scan(0, 0, img.bitmap.width, img.bitmap.height, function (x, y, idx) { @@ -16,16 +17,10 @@ function recolor(img, col) { }) } -/* -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' -*/ -function genFileName(...args) { - return args.filter(function(val) {return val}).join('_')+'_001.png'; -} -function fromIcons(filename) { - return `./icons/${filename}`; -} +/* 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' */ +function genFileName(...args) { return args.filter(function(val) {return val}).join('_')+'_001.png' } +function fromIcons(filename) { return `./icons/${filename}` } let cache = {}; module.exports = async (app, req, res) => { @@ -43,6 +38,10 @@ module.exports = async (app, req, res) => { let col2 = req.query.col2 || account[11] || 3; let outline = req.query.glow || account[28] || "0"; + // 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 = [] + let sizeParam = req.query.size && !isNaN(req.query.size) if (outline == "0") outline = false; @@ -73,7 +72,7 @@ module.exports = async (app, req, res) => { let iconCode = `${req.query.form == "cursed" ? "cursed" : form}-${iconID}-${col1}-${col2}-${outline ? 1 : 0}` - if (!sizeParam && cache[iconCode]) { + if (!sizeParam && !glowOffset.length && cache[iconCode]) { clearTimeout(cache[iconCode].timeoutID); cache[iconCode].timeoutID = setTimeout(function() {delete cache[iconCode]}, 600000); return res.end(cache[iconCode].value); @@ -82,11 +81,12 @@ module.exports = async (app, req, res) => { let useExtra = false let originalOffset = icons[icon].spriteOffset; - const minusOrigOffset = function(x, y) { return x - originalOffset[y] } + let minusOrigOffset = function(x, y) { return x - originalOffset[y] } let offset = icons[glow].spriteOffset.map(minusOrigOffset); let robotLeg1, robotLeg2, robotLeg3, robotLeg3b, robotLeg2b, robotLeg1b, robotLeg1c; let robotOffset1, robotOffset2, robotOffset3, robotOffset1b, robotOffset2b, robotOffset3b; let robotGlow1, robotGlow2, robotGlow3; + 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')}); @@ -101,6 +101,8 @@ module.exports = async (app, req, res) => { 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])) + + if (!glowOffset.length) glowOffset = offsets[form][+iconID] || [] } res.contentType('image/png'); @@ -154,14 +156,14 @@ module.exports = async (app, req, res) => { await Jimp.read(new Jimp(robotLeg1)).then(rob => { rob.rotate(-45) recolor(rob, col1) - rob.composite(robotGlow1, (robotOffset1[2] - robotOffset1b[2]) + 1, (robotOffset1[3] - robotOffset1b[3]) / 2, { mode: Jimp.BLEND_DESTINATION_OVER }) + rob.composite(robotGlow1, (robotOffset1[2] - robotOffset1b[2]) + (glowOffset[0] || 1), ((robotOffset1[3] - robotOffset1b[3]) / 2) + (glowOffset[1] || 0), { mode: Jimp.BLEND_DESTINATION_OVER }) robotLeg1 = rob }) await Jimp.read(new Jimp(robotLeg2)).then(rob => { rob.rotate(45) recolor(rob, col1) - rob.composite(robotGlow2, (robotOffset2[2] - robotOffset2b[2]) / 2, (robotOffset2[3] - robotOffset2b[3]) / 2, { mode: Jimp.BLEND_DESTINATION_OVER }) + rob.composite(robotGlow2, ((robotOffset2[2] - robotOffset2b[2]) / 4) + (glowOffset[4] || 0), ((robotOffset2[3] - robotOffset2b[3]) / 2) + (glowOffset[5] || 0), { mode: Jimp.BLEND_DESTINATION_OVER }) robotLeg2 = rob }) @@ -171,7 +173,7 @@ module.exports = async (app, req, res) => { await Jimp.read(new Jimp(robotLeg3)).then(rob => { recolor(rob, col1) - rob.composite(robotGlow3, (robotOffset3[2] - robotOffset3b[2]) / 2 - 2, (robotOffset3[3] - robotOffset3b[3]) / 2, { mode: Jimp.BLEND_DESTINATION_OVER }) + rob.composite(robotGlow3, ((robotOffset3[2] - robotOffset3b[2]) / 2) + (glowOffset[2] || 0), ((robotOffset3[3] - robotOffset3b[3]) / 2) + (glowOffset[3] || 0), { mode: Jimp.BLEND_DESTINATION_OVER }) robotLeg3 = rob }) @@ -223,13 +225,13 @@ module.exports = async (app, req, res) => { await Jimp.read(new Jimp(robotLeg1)).then(rob => { recolor(rob, col1) - rob.composite(robotGlow1, (robotOffset1[2] - robotOffset1b[2]) / 2, (robotOffset1[3] - robotOffset1b[3]) / 4, { mode: Jimp.BLEND_DESTINATION_OVER }) + rob.composite(robotGlow1, ((robotOffset1[2] - robotOffset1b[2]) / 2) + (glowOffset[2] || 0), ((robotOffset1[3] - robotOffset1b[3]) / 4) + (glowOffset[3] || 0), { mode: Jimp.BLEND_DESTINATION_OVER }) robotLeg1 = rob }) await Jimp.read(new Jimp(robotLeg2)).then(rob => { recolor(rob, col1) - rob.composite(robotGlow2, (robotOffset2[2] - robotOffset2b[2]) / 6, (robotOffset2[3] - robotOffset2b[3]) / 6, { mode: Jimp.BLEND_DESTINATION_OVER }) + rob.composite(robotGlow2, ((robotOffset2[2] - robotOffset2b[2]) / 6) + (glowOffset[0] || 0), ((robotOffset2[3] - robotOffset2b[3]) / 6) + (glowOffset[1] || 0), { mode: Jimp.BLEND_DESTINATION_OVER }) rob.rotate(-40) robotLeg2 = rob }) @@ -244,7 +246,7 @@ module.exports = async (app, req, res) => { await Jimp.read(new Jimp(robotLeg3)).then(rob => { recolor(rob, col1) - rob.composite(robotGlow3, (robotOffset3[2] - robotOffset3b[2]) / 2, (robotOffset3[3] - robotOffset3b[3]) / 2, { mode: Jimp.BLEND_DESTINATION_OVER }) + rob.composite(robotGlow3, ((robotOffset3[2] - robotOffset3b[2]) / 2) + (glowOffset[4] || 0), ((robotOffset3[3] - robotOffset3b[3]) / 2) + (glowOffset[5] || 0), { mode: Jimp.BLEND_DESTINATION_OVER }) robotLeg3 = rob }) @@ -255,7 +257,6 @@ module.exports = async (app, req, res) => { 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 @@ -269,16 +270,13 @@ module.exports = async (app, req, res) => { if (ic.bitmap.height == '300') ic.autocrop(1, false) - if (!outline && sizeParam) { + if (sizeParam) { let imgSize = Math.round(req.query.size) if (imgSize < 32) imgSize = 32 if (imgSize > 512) imgSize = 512 - ic.resize(imgSize, imgSize) - } - - if (sizeParam) { if (ic.bitmap.width > ic.bitmap.height) ic.contain(ic.bitmap.width, ic.bitmap.width, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE) else if (ic.bitmap.width < ic.bitmap.height) ic.contain(ic.bitmap.height, ic.bitmap.height, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE) + ic.resize(imgSize, Jimp.AUTO) } let finalSize = [ic.bitmap.width, ic.bitmap.height] diff --git a/icons/offsets.json b/icons/offsets.json new file mode 100644 index 0000000..249d5d8 --- /dev/null +++ b/icons/offsets.json @@ -0,0 +1,35 @@ +{ + "robot": { + "3": [0, 0, 0, 0, -100], + "5": [4, -4, 10, 8, -100], + "6": [5, -1, 0, 0, -100], + "7": [-23, -2, 14, 5], + "8": [5, -2, -3, 0, -100], + "9": [5, -3], + "10": [-22, -2, 12, 3], + "11": [-1, 0, -2], + "12": [5, -2, 6, 5], + "13": [-3, 2, -7, -4], + "15": [0, 0, -7, -2], + "16": [1, 0, 0, 0, -100], + "17": [1, 0, 0, 0, -100], + "18": [-6, 4, -4, 0], + "19": [-10, 0, 14, 4], + "20": [1, 0, 10, 5], + "21": [10, -8, 12, 3, -5, 2], + "22": [-10, 6, -12 ,3], + "23": [-18, 14, -4, 0], + "24": [4, -2, -4], + "25": [15, -10, -1, 2], + "26": [-1, 0, 5] + }, + + "spider": { + "9": [0, 3], + "10": [8, 5], + "11": [1, 3], + "14": [2, 1], + "15": [2, 20, 0, 14], + "17": [0, 1] + } +} \ No newline at end of file From 29f8c0b9bc94b37cbc2c5b335df2eb8015515039 Mon Sep 17 00:00:00 2001 From: Colon <56617416+GDColon@users.noreply.github.com> Date: Sun, 21 Jun 2020 00:21:14 -0400 Subject: [PATCH 2/5] Fixed broken robots/spiders with the power of hardcoding x2 --- api/icon.js | 4 ++-- icons/offsets.json | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/icon.js b/api/icon.js index 43da891..7aca2a0 100644 --- a/api/icon.js +++ b/api/icon.js @@ -284,7 +284,7 @@ module.exports = async (app, req, res) => { ic.getBuffer(Jimp.AUTO, function (err, buff) { if (!outline) { - if (!sizeParam) { + if (!sizeParam && !glowOffset.length) { cache[iconCode] = { value: buff, timeoutID: setTimeout(function() {delete cache[iconCode]}, 600000) @@ -324,7 +324,7 @@ module.exports = async (app, req, res) => { img.src = buff; const buffer = canvas.toBuffer(); - if (!sizeParam) { + if (!sizeParam && !glowOffset.length) { cache[iconCode] = { value: buffer, timeoutID: setTimeout(function() {delete cache[iconCode]}, 600000) diff --git a/icons/offsets.json b/icons/offsets.json index 249d5d8..b7738fa 100644 --- a/icons/offsets.json +++ b/icons/offsets.json @@ -1,6 +1,6 @@ { "robot": { - "3": [0, 0, 0, 0, -100], + "3": [-2, 0, 0, 0, -100], "5": [4, -4, 10, 8, -100], "6": [5, -1, 0, 0, -100], "7": [-23, -2, 14, 5], @@ -13,14 +13,14 @@ "15": [0, 0, -7, -2], "16": [1, 0, 0, 0, -100], "17": [1, 0, 0, 0, -100], - "18": [-6, 4, -4, 0], - "19": [-10, 0, 14, 4], + "18": [-6, 4, -4, 0, -100], + "19": [-21, 0, 14, 4], "20": [1, 0, 10, 5], "21": [10, -8, 12, 3, -5, 2], - "22": [-10, 6, -12 ,3], - "23": [-18, 14, -4, 0], + "22": [-10, 6, -12, 3, -100], + "23": [-18, 16, -4], "24": [4, -2, -4], - "25": [15, -10, -1, 2], + "25": [12, -9, -1, 2], "26": [-1, 0, 5] }, @@ -29,7 +29,7 @@ "10": [8, 5], "11": [1, 3], "14": [2, 1], - "15": [2, 20, 0, 14], - "17": [0, 1] + "15": [3, 20, 0, 14], + "17": [1, 1] } } \ No newline at end of file From e4e6555ab2ca25a49b7fb5a7e849a9262b375656 Mon Sep 17 00:00:00 2001 From: Colon <56617416+GDColon@users.noreply.github.com> Date: Mon, 22 Jun 2020 21:58:33 -0400 Subject: [PATCH 3/5] Added UFO domes. I want to kill myself. that was way fucking harder than it should have been --- api/icon.js | 104 ++++++++++++++++++------------------ html/api.html | 1 + html/iconkit.html | 3 +- icons/iconkit/robot-01.png | Bin 4876 -> 5352 bytes icons/iconkit/robot-02.png | Bin 4224 -> 4779 bytes icons/iconkit/robot-03.png | Bin 5353 -> 4964 bytes icons/iconkit/robot-04.png | Bin 5783 -> 5433 bytes icons/iconkit/robot-05.png | Bin 6409 -> 6726 bytes icons/iconkit/robot-06.png | Bin 6199 -> 6245 bytes icons/iconkit/robot-07.png | Bin 6917 -> 6216 bytes icons/iconkit/robot-08.png | Bin 6463 -> 5429 bytes icons/iconkit/robot-09.png | Bin 8278 -> 6732 bytes icons/iconkit/robot-10.png | Bin 6536 -> 5077 bytes icons/iconkit/robot-11.png | Bin 5193 -> 5470 bytes icons/iconkit/robot-12.png | Bin 6497 -> 5608 bytes icons/iconkit/robot-13.png | Bin 7402 -> 7351 bytes icons/iconkit/robot-14.png | Bin 6397 -> 5488 bytes icons/iconkit/robot-15.png | Bin 5517 -> 6597 bytes icons/iconkit/robot-16.png | Bin 6936 -> 5933 bytes icons/iconkit/robot-17.png | Bin 8038 -> 5941 bytes icons/iconkit/robot-18.png | Bin 7502 -> 7328 bytes icons/iconkit/robot-19.png | Bin 8611 -> 5523 bytes icons/iconkit/robot-20.png | Bin 8375 -> 6935 bytes icons/iconkit/robot-21.png | Bin 7688 -> 6824 bytes icons/iconkit/robot-22.png | Bin 6190 -> 6274 bytes icons/iconkit/robot-23.png | Bin 5817 -> 5169 bytes icons/iconkit/robot-24.png | Bin 7440 -> 6052 bytes icons/iconkit/robot-25.png | Bin 6703 -> 6508 bytes icons/iconkit/robot-26.png | Bin 6849 -> 5832 bytes icons/iconkit/spider-01.png | Bin 3890 -> 4408 bytes icons/iconkit/spider-02.png | Bin 6048 -> 5765 bytes icons/iconkit/spider-03.png | Bin 4180 -> 5492 bytes icons/iconkit/spider-04.png | Bin 3951 -> 4231 bytes icons/iconkit/spider-05.png | Bin 6214 -> 6383 bytes icons/iconkit/spider-06.png | Bin 5329 -> 5351 bytes icons/iconkit/spider-07.png | Bin 6145 -> 5891 bytes icons/iconkit/spider-08.png | Bin 4798 -> 4361 bytes icons/iconkit/spider-09.png | Bin 5528 -> 5133 bytes icons/iconkit/spider-10.png | Bin 5691 -> 5030 bytes icons/iconkit/spider-11.png | Bin 6725 -> 6625 bytes icons/iconkit/spider-12.png | Bin 5483 -> 6066 bytes icons/iconkit/spider-13.png | Bin 9717 -> 6768 bytes icons/iconkit/spider-14.png | Bin 7047 -> 5788 bytes icons/iconkit/spider-15.png | Bin 4353 -> 4036 bytes icons/iconkit/spider-16.png | Bin 3375 -> 5134 bytes icons/iconkit/spider-17.png | Bin 6539 -> 5667 bytes 46 files changed, 54 insertions(+), 54 deletions(-) diff --git a/api/icon.js b/api/icon.js index 7aca2a0..40cbb0d 100644 --- a/api/icon.js +++ b/api/icon.js @@ -5,7 +5,8 @@ const path = require('path'); const icons = require('../icons/gameSheet.json'); const colors = require('../misc/colors.json'); const forms = require('../icons/forms.json') -const offsets = require('../icons/offsets.json') +const offsets = require('../icons/offsets.json'); +const { finished } = require('stream'); function recolor(img, col) { return img.scan(0, 0, img.bitmap.width, img.bitmap.height, function (x, y, idx) { @@ -19,7 +20,7 @@ function recolor(img, col) { /* 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' */ -function genFileName(...args) { return args.filter(function(val) {return val}).join('_')+'_001.png' } +function genFileName(...args) { return args.filter(function(val) {return val}).join('_') +'_001.png' } function fromIcons(filename) { return `./icons/${filename}` } let cache = {}; @@ -42,6 +43,7 @@ module.exports = async (app, req, res) => { let glowOffset = (req.query.off || "").split(",").map(x => Number(x)) if (!glowOffset.some(x => x != 0)) glowOffset = [] + let topless = form == "bird" && req.query.topless let sizeParam = req.query.size && !isNaN(req.query.size) if (outline == "0") outline = false; @@ -70,7 +72,7 @@ module.exports = async (app, req, res) => { if (!colors[col1]) col1 = 0 if (!colors[col2]) col2 = 3 - let iconCode = `${req.query.form == "cursed" ? "cursed" : form}-${iconID}-${col1}-${col2}-${outline ? 1 : 0}` + let iconCode = `${req.query.form == "cursed" ? "cursed" : form}${topless ? "topless" : ""}-${iconID}-${col1}-${col2}-${outline ? 1 : 0}` if (!sizeParam && !glowOffset.length && cache[iconCode]) { clearTimeout(cache[iconCode].timeoutID); @@ -85,7 +87,8 @@ module.exports = async (app, req, res) => { let offset = icons[glow].spriteOffset.map(minusOrigOffset); let robotLeg1, robotLeg2, robotLeg3, robotLeg3b, robotLeg2b, robotLeg1b, robotLeg1c; let robotOffset1, robotOffset2, robotOffset3, robotOffset1b, robotOffset2b, robotOffset3b; - let robotGlow1, robotGlow2, robotGlow3; + let robotGlow1, robotGlow2, robotGlow3 + let ufoTop, ufoOffset, ufoCoords, ufoSprite if (isSpecial) { const legs = [1,2,3].map(function(val) {return genImageName(`0${val+1}`)}); @@ -128,10 +131,14 @@ module.exports = async (app, req, res) => { 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 }) - if (form == "ufo") { //ufo top WIP - ic.contain(iconSize[0], iconSize[1] * 1.1, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE) - //ic.contain(iconSize[0], 300, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_BOTTOM) - //ic.composite(ufoTop, (iconSize[0] / 2) - (size[0] / 2) + 7, iconSize[1] + topOffset[3] + 30, {mode: Jimp.BLEND_DESTINATION_OVER}) + 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}) } if (form == "robot" || req.query.form == "cursed") { @@ -189,7 +196,6 @@ module.exports = async (app, req, res) => { } - else if (form == "spider") { let spiderBody; @@ -264,36 +270,38 @@ module.exports = async (app, req, res) => { ic.composite(robotLeg1, 100 + (iconSize[0] / 2) - (robotOffset1[2]) + robotOffset1[0] + 7, (iconSize[1] / 2) - (robotOffset1[3]) - robotOffset1[1] + 70) } - if (useExtra) ic.composite(extra, imgOff + (iconSize[0] / 2) - (size2[0] / 2) + offset2[0], (iconSize[1] / 2) - (size2[1] / 2) - offset2[1]) - if (form != "ufo") ic.autocrop(0.01, false) - if (form == "swing") ic.resize(120, 111) - - if (ic.bitmap.height == '300') ic.autocrop(1, false) - - if (sizeParam) { - let imgSize = Math.round(req.query.size) - if (imgSize < 32) imgSize = 32 - if (imgSize > 512) imgSize = 512 - if (ic.bitmap.width > ic.bitmap.height) ic.contain(ic.bitmap.width, ic.bitmap.width, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE) - else if (ic.bitmap.width < ic.bitmap.height) ic.contain(ic.bitmap.height, ic.bitmap.height, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE) - ic.resize(imgSize, Jimp.AUTO) - } + if (useExtra) ic.composite(extra, imgOff + (iconSize[0] / 2) - (size2[0] / 2) + offset2[0], (iconSize[1] / 2) - (size2[1] / 2) - offset2[1] + (form == "bird" ? 300 - iconSize[1] : 0)) let finalSize = [ic.bitmap.width, ic.bitmap.height] - ic.getBuffer(Jimp.AUTO, function (err, buff) { - - if (!outline) { + function finish(img) { + img.autocrop(0.01, false) + if (form == "swing") b.resize(120, 111) + if (img.bitmap.height == 300) ic.autocrop(1, false) + if (sizeParam) { + let imgSize = Math.round(req.query.size) + if (imgSize < 32) imgSize = 32 + if (imgSize > 512) imgSize = 512 + if (img.bitmap.width > img.bitmap.height) img.contain(img.bitmap.width, img.bitmap.width, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE) + else if (img.bitmap.width < img.bitmap.height) img.contain(img.bitmap.height, img.bitmap.height, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE) + img.resize(imgSize, Jimp.AUTO) + } + img.getBuffer(Jimp.AUTO, (err, buffer) => { if (!sizeParam && !glowOffset.length) { cache[iconCode] = { - value: buff, + value: buffer, timeoutID: setTimeout(function() {delete cache[iconCode]}, 600000) } } - return res.end(buff) - } + return res.end(buffer, 'base64') + }) + } - else { + if (!outline) return finish(ic) + + else { + + ic.getBuffer(Jimp.AUTO, function (err, buff) { const Canvas = require('canvas') , Image = Canvas.Image @@ -316,35 +324,25 @@ module.exports = async (app, req, res) => { ctx.globalCompositeOperation = "source-over"; ctx.imageSmoothingEnabled = false; + // 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) + } + ctx.drawImage(img, x, y) } img.onerror = err => { throw err } - img.src = buff; - const buffer = canvas.toBuffer(); + img.src = buff - if (!sizeParam && !glowOffset.length) { - cache[iconCode] = { - value: buffer, - timeoutID: setTimeout(function() {delete cache[iconCode]}, 600000) - } - return res.end(buffer, 'base64') - } - - else { - let imgSize = Math.round(req.query.size) - if (imgSize < 32) imgSize = 32 - if (imgSize > 512) imgSize = 512 - - Jimp.read(buffer).then(i => { - i.resize(imgSize, imgSize) - i.getBuffer(Jimp.AUTO, (err, b) => res.end(b)) - }) - } - - } - }) + Jimp.read(canvas.toBuffer()).then(b => { + return finish(b) + }) + }) + } }) }) } diff --git a/html/api.html b/html/api.html index 18bffb8..87dc73c 100644 --- a/html/api.html +++ b/html/api.html @@ -722,6 +722,7 @@
col2: The ID of the secondary color to use
glow: If the icon should have a glow/outline (0 = off, anything else = on)
size: The size (in pixels) the icon should be, in case you don't want the default. Will always be square
+topless: Removes the glass 'dome' from generated UFOs (legacy)
noUser: Disables fetching the icon from the GD servers. Slightly faster, but comes at the cost of having to build icons from the ground up using the parameters listed above. It completely ignores the entered username and always returns the default icon
diff --git a/html/iconkit.html b/html/iconkit.html index 27dcb4e..778e1a8 100644 --- a/html/iconkit.html +++ b/html/iconkit.html @@ -32,7 +32,8 @@All sprites/assets belong to RobTop Games.
+All sprites/assets belong to RobTop Games.
+Y_Co-ReX?o
zmsxN&b$GBXBt>Nqh{QIhG8XQ>dPSwEd_*zX&`}0 J-v0(%rr8e!o`6ca8pk`bj@L+
z<-V}6um?S#f{oBu5IKsXGZ}_5^rD%|j*j+a)}P>9T*_Oid{g5>ayf~tbBLa?ro{Wo
z_8gmMUtLt1o}R84bPG7LtLE>VyO=pj-^FELRgrAoyZ?1QpCXet_SJu32kaMm2|2{&
zrKqo3FNIm^c>
v5@#Jq)%X4kvZuzZt
zwTbPe9!%DY7qZ-pqxs4PXt}qB&2OZbCnhH?8eQ4^=e%gnKqDMQ9+lq`b~)Hx*#(EO
z8ae#4KGPYlOhrXyY-*Z**~DaUc(}M96;$Z?Kop{gfR9a2_a+hlGM_xj$j(j}cm6v3P?p>IxuyjB
zZ9H8~!FZb#t`~Ivlc=71-rnBV0W+FQ#FV+rX`|t
5sIc>77!A$wz8`Ci*-{ztAja$dDKRy
z<3Uq_xFMcohh%H)3gc4EyntSeUFE}K=~&*Ir&1-$9e5h@jn}9;>EN;L&dc3kU`9IEndbm
z_Cq3o_ZS#Gb?Ox3sP1ja-nv7TZ{NJh%+HU3J*
PMqrTHoy~O56Rf4R$hSsKw7TEX@&Pp@J~cTR
z_m}phh|`6pFRo7*zzBDAbPU*@y9A|9eDvskflH_k_TMr2bY+ik)L_ORgO#xm62?g~
zh(|BJwY`0csDtk5=^KbQ27lmkzq5ac+%dWkpxU$ETzYTCn07vk?*3a})yKp|{vPKY#q_2}2Q_
zCk{#l!0E_1-T*g#ek<+Dbc3-p-Ztq