From a534e7c4cfc147e423616daf96c3dd0903d0e1e5 Mon Sep 17 00:00:00 2001 From: TheEssem Date: Fri, 10 Jan 2020 13:40:25 -0600 Subject: [PATCH] Added optimization to many image commands, updated packages --- commands/9gag.js | 2 +- commands/bandicam.js | 2 +- commands/caption.js | 2 +- commands/deviantart.js | 2 +- commands/funky.js | 2 +- commands/gamexplain.js | 2 +- commands/haah.js | 2 +- commands/hooh.js | 2 +- commands/hypercam.js | 2 +- commands/ifunny.js | 2 +- commands/memecenter.js | 2 +- commands/scott.js | 2 +- commands/shutterstock.js | 2 +- commands/trump.js | 2 +- commands/waaw.js | 2 +- commands/wdt.js | 2 +- commands/woow.js | 2 +- package-lock.json | 54 +++++++++++++++++----------------------- package.json | 4 +-- 19 files changed, 42 insertions(+), 50 deletions(-) diff --git a/commands/9gag.js b/commands/9gag.js index e9a4cff..c07957e 100644 --- a/commands/9gag.js +++ b/commands/9gag.js @@ -8,7 +8,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add a 9GAG watermark!`; const watermark = "./assets/images/9gag.png"; - const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite"); + const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(data); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/bandicam.js b/commands/bandicam.js index 664ecc1..50db095 100644 --- a/commands/bandicam.js +++ b/commands/bandicam.js @@ -10,7 +10,7 @@ exports.run = async (message) => { const watermark = "./assets/images/bandicam.png"; gm(image.data).size(async (error, size) => { if (error) throw error; - const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite"); + const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(data); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/caption.js b/commands/caption.js index fbcc468..98049a3 100644 --- a/commands/caption.js +++ b/commands/caption.js @@ -19,7 +19,7 @@ exports.run = async (message, args) => { if (error) throw error; gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).stream(async (error, output2) => { if (error) throw error; - const command3 = gm(output2).out("-alpha", "set").background("none").out("(").out(path).out("-coalesce").out(")").out("-set", "page", "%[fx:u.w]x%[fx:u.h+v.h]+%[fx:t?(u.w-v.w)/2:0]+%[fx:t?u.h:0]").out("-coalesce").out("null:").out("-insert", 1).out("-layers", "composite").out("-loop", "0"); + const command3 = gm(output2).out("-alpha", "set").background("none").out("(").out(path).out("-coalesce").out(")").out("-set", "page", "%[fx:u.w]x%[fx:u.h+v.h]+%[fx:t?(u.w-v.w)/2:0]+%[fx:t?u.h:0]").out("-coalesce").out("null:").out("-insert", 1).out("-layers", "composite").out("-layers", "optimize"); const outputFinal = await gmToBuffer(command3, image.type); await processMessage.delete(); return message.channel.createMessage("", { diff --git a/commands/deviantart.js b/commands/deviantart.js index 8dd881b..7bc9e28 100644 --- a/commands/deviantart.js +++ b/commands/deviantart.js @@ -10,7 +10,7 @@ exports.run = async (message) => { const watermark = "./assets/images/deviantart.png"; gm(image.data).size(async (error, size) => { if (error) throw error; - const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite"); + const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(data); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/funky.js b/commands/funky.js index 1cc257e..95f8eae 100644 --- a/commands/funky.js +++ b/commands/funky.js @@ -10,7 +10,7 @@ exports.run = async (message) => { const watermark = "./assets/images/funky.png"; gm(image.data).size(async (error, size) => { if (error) throw error; - const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite"); + const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(data); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/gamexplain.js b/commands/gamexplain.js index 0568a49..87cb98e 100644 --- a/commands/gamexplain.js +++ b/commands/gamexplain.js @@ -11,7 +11,7 @@ exports.run = async (message) => { const template = "./assets/images/gamexplain.png"; const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`; require("util").promisify(fs.writeFile)(path, image.data); - const command = gm(template).background("white").out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("1181x571!").coalesce().out(")").compose("over").gravity("Center").out("-geometry", "+0+40").out("-layers", "composite"); + const command = gm(template).background("white").out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("1181x571!").coalesce().out(")").compose("over").gravity("Center").out("-geometry", "+0+40").out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(command, image.type); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/haah.js b/commands/haah.js index 2fa6403..9358185 100644 --- a/commands/haah.js +++ b/commands/haah.js @@ -17,7 +17,7 @@ exports.run = async (message) => { if (error) throw error; gm(data2).flop().write(data, async (error) => { if (error) throw error; - const command = gm(data2).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data).coalesce().out(")").geometry(`+${size.width / 2}+0`).out("-layers", "Composite"); + const command = gm(data2).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data).coalesce().out(")").geometry(`+${size.width / 2}+0`).out("-layers", "Composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(command); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/hooh.js b/commands/hooh.js index f2cae0e..b81d315 100644 --- a/commands/hooh.js +++ b/commands/hooh.js @@ -17,7 +17,7 @@ exports.run = async (message) => { if (error) throw error; gm(data2).flip().write(data, async (error) => { if (error) throw error; - const command = gm(data).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data2).coalesce().out(")").geometry(`+0+${size.height / 2}`).out("-layers", "Composite"); + const command = gm(data).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data2).coalesce().out(")").geometry(`+0+${size.height / 2}`).out("-layers", "Composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(command); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/hypercam.js b/commands/hypercam.js index eb76b71..81dec80 100644 --- a/commands/hypercam.js +++ b/commands/hypercam.js @@ -10,7 +10,7 @@ exports.run = async (message) => { const watermark = "./assets/images/hypercam.png"; gm(image.data).size(async (error, size) => { if (error) throw error; - const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite"); + const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(data); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/ifunny.js b/commands/ifunny.js index 6b62935..4b18dd6 100644 --- a/commands/ifunny.js +++ b/commands/ifunny.js @@ -10,7 +10,7 @@ exports.run = async (message) => { const watermark = "./assets/images/ifunny.png"; gm(image.data).size(async (error, size) => { if (error) throw error; - const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite"); + const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(data); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/memecenter.js b/commands/memecenter.js index d8bd643..08cf577 100644 --- a/commands/memecenter.js +++ b/commands/memecenter.js @@ -11,7 +11,7 @@ exports.run = async (message) => { let resultBuffer; gm(image.data).size(async (error, size) => { if (error) throw error; - const command = gm(image.data).coalesce().background("white").extent(size.width, size.height + 15).out("null:").out(watermark).gravity("SouthEast").compose("over").out("-layers", "composite"); + const command = gm(image.data).coalesce().background("white").extent(size.width, size.height + 15).out("null:").out(watermark).gravity("SouthEast").compose("over").out("-layers", "composite").out("-layers", "optimize"); const output = await gmToBuffer(command, image.type); gm(output).size(async (error, size2) => { if (error) throw error; diff --git a/commands/scott.js b/commands/scott.js index b6b8870..41d2b8e 100644 --- a/commands/scott.js +++ b/commands/scott.js @@ -11,7 +11,7 @@ exports.run = async (message) => { const template = "./assets/images/scott.png"; const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`; require("util").promisify(fs.writeFile)(path, image.data); - const command = gm(template).out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("415x234!").coalesce().out("+distort", "Perspective", "0,0 129,187 415,0 517,182 415,234 517,465 0,234 132,418").out(")").compose("over").gravity("Center").geometry("-238-98").out("-layers", "composite"); + const command = gm(template).out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("415x234!").coalesce().out("+distort", "Perspective", "0,0 129,187 415,0 517,182 415,234 517,465 0,234 132,418").out(")").compose("over").gravity("Center").geometry("-238-98").out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(command, image.type); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/shutterstock.js b/commands/shutterstock.js index f7ab5f4..cd4fad8 100644 --- a/commands/shutterstock.js +++ b/commands/shutterstock.js @@ -10,7 +10,7 @@ exports.run = async (message) => { const watermark = "./assets/images/shutterstock.png"; gm(image.data).size(async (error, size) => { if (error) throw error; - const command = gm(image.data).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite"); + const command = gm(image.data).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); const output = await gmToBuffer(command); return message.channel.createMessage("", { file: output, diff --git a/commands/trump.js b/commands/trump.js index f615440..febf731 100644 --- a/commands/trump.js +++ b/commands/trump.js @@ -11,7 +11,7 @@ exports.run = async (message) => { const template = "./assets/images/trump.png"; const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`; require("util").promisify(fs.writeFile)(path, image.data); - const command = gm(template).background("white").out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("365x179!").coalesce().out("+distort", "Perspective", "0,0 207,268 365,0 548,271 365,179 558,450 0,179 193,450").out(")").compose("over").gravity("Center").geometry("-217-135").out("-layers", "composite"); + const command = gm(template).background("white").out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("365x179!").coalesce().out("+distort", "Perspective", "0,0 207,268 365,0 548,271 365,179 558,450 0,179 193,450").out(")").compose("over").gravity("Center").geometry("-217-135").out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(command, image.type); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/waaw.js b/commands/waaw.js index 8a46643..7a997fd 100644 --- a/commands/waaw.js +++ b/commands/waaw.js @@ -17,7 +17,7 @@ exports.run = async (message) => { if (error) throw error; gm(data2).flop().write(data, async (error) => { if (error) throw error; - const command = gm(data).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data2).coalesce().out(")").geometry(`+${size.width / 2}+0`).out("-layers", "Composite"); + const command = gm(data).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data2).coalesce().out(")").geometry(`+${size.width / 2}+0`).out("-layers", "Composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(command); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/wdt.js b/commands/wdt.js index 4720ddc..0cca6ee 100644 --- a/commands/wdt.js +++ b/commands/wdt.js @@ -11,7 +11,7 @@ exports.run = async (message) => { const template = "./assets/images/whodidthis.png"; const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`; require("util").promisify(fs.writeFile)(path, image.data); - const command = gm(template).coalesce().out("null:").out(path).gravity("Center").resize("374x374>").out("-layers", "composite"); + const command = gm(template).coalesce().out("null:").out(path).gravity("Center").resize("374x374>").out("-layers", "composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(command, image.type); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/woow.js b/commands/woow.js index 769902e..c47a4f3 100644 --- a/commands/woow.js +++ b/commands/woow.js @@ -17,7 +17,7 @@ exports.run = async (message) => { if (error) throw error; gm(data2).flip().write(data, async (error) => { if (error) throw error; - const command = gm(data2).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data).coalesce().out(")").geometry(`+0+${size.height / 2}`).out("-layers", "Composite"); + const command = gm(data2).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data).coalesce().out(")").geometry(`+0+${size.height / 2}`).out("-layers", "Composite").out("-layers", "optimize"); const resultBuffer = await gmToBuffer(command); return message.channel.createMessage("", { file: resultBuffer, diff --git a/package-lock.json b/package-lock.json index 85ea408..ece9e04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "esmbot", - "version": "1.0.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -25,9 +25,9 @@ } }, "@types/node": { - "version": "12.12.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.14.tgz", - "integrity": "sha512-u/SJDyXwuihpwjXy7hOOghagLEV1KdAST6syfnOk6QZAMzZuWZqXy5aYYZbh8Jdpd4escVFP0MvftHNDb9pruA==" + "version": "13.1.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.6.tgz", + "integrity": "sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg==" }, "acorn": { "version": "6.1.1", @@ -160,11 +160,6 @@ "lodash": "^4.17.11" } }, - "async-limiter": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", - "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" - }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -710,13 +705,13 @@ "integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA==" }, "eris": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/eris/-/eris-0.11.1.tgz", - "integrity": "sha512-Ct32iXjESOnmklxZCEA281BQsTlAsS9xzQkbGlnvzXshCjBptWJ5h8Oxbu67ui1DirsYs0WipB8EBC9ITQ5ZQA==", + "version": "0.11.2", + "resolved": "https://registry.npmjs.org/eris/-/eris-0.11.2.tgz", + "integrity": "sha512-OhccRcxrPiNUylTamrjIbZM6itKMLjNrwLIXGvNwQZj4CRVOOz9eUVIqOJULB713x1ezw7HoC8AEsnsMNUneDA==", "requires": { - "opusscript": "^0.0.4", - "tweetnacl": "^1.0.0", - "ws": "^7.1.2" + "opusscript": "^0.0.7", + "tweetnacl": "^1.0.1", + "ws": "^7.2.1" } }, "erlpack": { @@ -1538,9 +1533,9 @@ "integrity": "sha512-cBMXjSW+fjOb4tyaVHuaVE/A5TqkukDWiOfxxAjY+PEqmmBQlLwn+8OzwPiG3brouXKY5Un4pBjAeB6UToXHaQ==" }, "mongodb": { - "version": "3.3.5", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.3.5.tgz", - "integrity": "sha512-6NAv5gTFdwRyVfCz+O+KDszvjpyxmZw+VlmqmqKR2GmpkeKrKFRv/ZslgTtZba2dc9JYixIf99T5Gih7TIWv7Q==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.4.1.tgz", + "integrity": "sha512-juqt5/Z42J4DcE7tG7UdVaTKmUC6zinF4yioPfpeOSNBieWSK6qCY+0tfGQcHLKrauWPDdMZVROHJOa8q2pWsA==", "requires": { "bson": "^1.1.1", "require_optional": "^1.0.1", @@ -1549,13 +1544,13 @@ } }, "mongoose": { - "version": "5.7.13", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.7.13.tgz", - "integrity": "sha512-MoTCETTIfXU1PqIYc+YAkhSB3uzK5xseh6ysAUnoOowkqS66OjBJtsL/bcgAKi6XfMYkFU6M1abKyuL7k//xeg==", + "version": "5.8.6", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.8.6.tgz", + "integrity": "sha512-DbmcaD5skOojIlUrd78fXTI3FsF711CX8jaLdKGtL/7/N0rbPpjwyLXIYiHkq146DGkIDeBDLEPlcl6zfkjM6A==", "requires": { "bson": "~1.1.1", "kareem": "2.3.1", - "mongodb": "3.3.5", + "mongodb": "3.4.1", "mongoose-legacy-pluralize": "1.0.2", "mpath": "0.6.0", "mquery": "3.2.2", @@ -1798,9 +1793,9 @@ } }, "opusscript": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.4.tgz", - "integrity": "sha512-bEPZFE2lhUJYQD5yfTFO4RhbRZ937x6hRwBC1YoGacT35bwDVwKFP1+amU8NYfZL/v4EU7ZTU3INTqzYAnuP7Q==", + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.7.tgz", + "integrity": "sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==", "optional": true }, "os-homedir": { @@ -2826,12 +2821,9 @@ } }, "ws": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz", - "integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==", - "requires": { - "async-limiter": "^1.0.0" - } + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.1.tgz", + "integrity": "sha512-sucePNSafamSKoOqoNfBd8V0StlkzJKL2ZAhGQinCfNQ+oacw+Pk7lcdAElecBF2VkLNZRiIb5Oi1Q5lVUVt2A==" }, "xtend": { "version": "4.0.1", diff --git a/package.json b/package.json index 5d941e2..32c591d 100644 --- a/package.json +++ b/package.json @@ -17,13 +17,13 @@ "dblapi.js": "^2.3.0", "dotenv": "^8.2.0", "emoji-regex": "^8.0.0", - "eris": "^0.11.1", + "eris": "^0.11.2", "file-type": "^10.9.0", "gm": "^1.23.1", "jsqr": "^1.2.0", "moment": "^2.24.0", "moment-duration-format": "^2.3.2", - "mongoose": "^5.7.13", + "mongoose": "^5.8.6", "node-fetch": "^2.6.0", "qrcode": "^1.4.4", "retrotext": "github:TheEssem/retrotext",