commit a84e80de479222fe7e4f5cb3bbbc176fcc0e5391 Author: Mr-KayJayDee Date: Tue May 26 22:57:48 2020 +0200 Added first generations diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa6a87f --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +package-lock.json +test/ +all.js +pas fait/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..61e3944 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# discord-image-generation + +> discord-image-generation is a powerfull module that allow you to generate awesome images. \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..b2ac9e6 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "discord-image-generation", + "version": "0.1.0", + "description": "discord-image-generation is a powerfull module that allow you to generate awesome images.", + "main": "index.js", + "scripts": { + "test": "node test/index.js" + }, + "author": "Mr¤KayJayDee (https://github.com/Mr-KayJayDee)", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/Mr-KayJayDee/discord-image-generation.git" + }, + "bugs": { + "url": "https://github.com/Mr-KayJayDee/discord-image-generation/issues" + }, + "homepage": "https://github.com/Mr-KayJayDee/discord-image-generation#readme", + "keywords": [ + "discord", + "images", + "genaration" + ], + "dependencies": { + "canvas": "^2.6.1", + "discord.js": "^12.2.0", + "gifencoder": "^2.0.1", + "jimp": "^0.12.1" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..9c69868 --- /dev/null +++ b/src/index.js @@ -0,0 +1,2 @@ +const DiscordImageGeneration = require("./module/DIG") +module.exports = Object.assign(DiscordImageGeneration) \ No newline at end of file diff --git a/src/module/DIG.js b/src/module/DIG.js new file mode 100644 index 0000000..5d00abc --- /dev/null +++ b/src/module/DIG.js @@ -0,0 +1,310 @@ +const Canvas = require("canvas"); +const jimp = require("jimp"); +const GIFEncoder = require("gifencoder"); +const circle = require('@jimp/plugin-circle') +const configure = require('@jimp/custom') + +// load custom plugins +configure({ plugins: [circle] }, jimp); + +class DIG { + + static async beautiful(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let base = await jimp.read(__dirname +"/assets/beautiful.png"); + base.resize(376, 400); + let img = await jimp.read(image); + img.resize(84, 95); + base.composite(img, 258, 28); + base.composite(img, 258, 229); + let raw; + base.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async facepalm(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let canvas = Canvas.createCanvas(632, 357); + let ctx = canvas.getContext("2d"); + ctx.fillStyle = "black"; + ctx.fillRect(0, 0, 632, 357); + let avatar = await Canvas.loadImage(image); + ctx.drawImage(avatar, 199, 112, 235, 235); + let layer = await Canvas.loadImage(__dirname +"/assets/facepalm.png"); + ctx.drawImage(layer, 0, 0, 632, 357); + return canvas.toBuffer(); + } + + static async gay(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let bg = await Canvas.loadImage(__dirname +"/assets/gay.png"); + let img = await Canvas.loadImage(image); + const canvas = Canvas.createCanvas(400, 400); + const ctx = canvas.getContext("2d"); + ctx.drawImage(img, 0, 0, 400, 400); + ctx.drawImage(bg, 0, 0, 400, 400); + return canvas.toBuffer(); + } + + static async kiss(image1, image2) { + if (!image1) throw new Error("You must provide an image as a first argument."); + if (!image2) throw new Error("You must provide an image as a second argument."); + const canvas = Canvas.createCanvas(768, 574); + const ctx = canvas.getContext("2d"); + const background = await Canvas.loadImage(__dirname +"/assets/kiss.png"); + ctx.drawImage(background, 0, 0, canvas.width, canvas.height); + const avatar = await Canvas.loadImage(image1); + const avatar1 = await Canvas.loadImage(image2); + ctx.drawImage(avatar1, 370, 25, 200, 200); + ctx.drawImage(avatar, 150, 25, 200, 200); + return canvas.toBuffer(); + } + + static async rip(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + const canvas = Canvas.createCanvas(244, 253); + const ctx = canvas.getContext("2d"); + const background = await Canvas.loadImage(__dirname +"/assets/rip.png"); + ctx.drawImage(background, 0, 0, canvas.width, canvas.height); + const avatar = await Canvas.loadImage(image); + ctx.drawImage(avatar, 63, 110, 90, 90); + return canvas.toBuffer(); + } + + static async spank(image1, image2) { + if (!image1) throw new Error("You must provide an image as a first argument."); + if (!image2) throw new Error("You must provide an image as a second argument."); + let bg = await jimp.read(__dirname +"/assets/spank.png"); + image1 = await jimp.read(image1); + image2 = await jimp.read(image2); + bg.resize(500, 500); + image1.resize(140, 140); + image2.resize(120, 120); + bg.composite(image2, 350, 220); + bg.composite(image1, 225, 5); + let raw; + bg.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async batslap(image1, image2) { + if (!image1) throw new Error("You must provide an image as a first argument."); + if (!image2) throw new Error("You must provide an image as a second argument."); + let base = await jimp.read(__dirname+"/assets/batslap.png"); + image1 = await jimp.read(image1); + image2 = await jimp.read(image2); + image1.circle(); + image2.circle(); + base.resize(1000, 500); + image1.resize(220, 220); + image2.resize(200, 200); + base.composite(image2, 580, 260); + base.composite(image1, 350, 70); + let raw; + base.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async affect(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let base = await jimp.read(__dirname + "/assets/affect.png"); + let img = await jimp.read(image); + img.resize(200, 157); + base.composite(img, 180, 383); + let raw; + base.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async blur(image, level = 5) { + if (!image) throw new Error("You must provide an image as a first argument."); + image = await jimp.read(image); + image.blur(isNaN(level) ? 5 : parseInt(level)); + let raw; + image.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async greyscale(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + image = await jimp.read(image); + image.greyscale(); + let raw; + image.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async sepia(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + image = await jimp.read(image); + image.sepia(); + let raw; + image.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async invert(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + image = await jimp.read(image); + image.invert(); + let raw; + image.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async delete(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let bg = await jimp.read(__dirname + "/assets/delete.png"); + image = await jimp.read(image); + image.resize(195, 195); + bg.composite(image, 120, 135); + let raw; + bg.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async trash(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let bg = await jimp.read(__dirname +"/assets/trash.png"); + image = await jimp.read(image); + image.resize(309, 309); + image.blur(5); + bg.composite(image, 309, 0); + let raw; + bg.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async color(color = "#FFFFFF") { + const canvas = Canvas.createCanvas(2048, 2048); + const ctx = canvas.getContext("2d"); + ctx.fillStyle = color; + ctx.fillRect(0, 0, canvas.width, canvas.height); + return canvas.toBuffer(); + } + + static async hitler(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let bg = await jimp.read(__dirname + "/assets/hitler.png"); + let img = await jimp.read(image); + img.resize(140, 140); + bg.composite(img, 46, 43); + let raw; + bg.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async bed(image1, image2) { + if (!image1) throw new Error("You must provide an image as a first argument."); + if (!image2) throw new Error("You must provide an image as a second argument."); + let bg = await jimp.read(__dirname +"/assets/bed.png"); + image1 = await jimp.read(image1); + image2 = await jimp.read(image2); + image1.resize(100, 100); + image2.resize(70, 70); + let image3 = image1.clone().resize(70, 70); + bg.composite(image1, 25, 100); + bg.composite(image1, 25, 300); + bg.composite(image3, 53, 450); + bg.composite(image2, 53, 575); + let raw; + bg.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async wanted(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let base = await jimp.read(__dirname + "/assets/wanted.png"); + let img = await jimp.read(image); + img.resize(447, 447); + base.composite(img, 145, 282); + let raw; + base.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async trigger(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + const base = await Canvas.loadImage(__dirname +"/assets/triggered.png"); + const img = await Canvas.loadImage(image); + const GIF = new GIFEncoder(256, 310) + GIF.start(); + GIF.setRepeat(0); + GIF.setDelay(15); + const canvas = Canvas.createCanvas(256, 310); + const ctx = canvas.getContext('2d'); + const BR = 20; + const LR = 10; + for (var i = 0; i < 9; i++) { + ctx.clearRect(0, 0, 256, 310); + ctx.drawImage(img, Math.floor(Math.random() * BR) - BR, Math.floor(Math.random() * BR) - BR, 256 + BR, 310 - 54 + BR); + ctx.fillStyle = '#FF000033'; + ctx.fillRect(0, 0, 256, 310); + ctx.drawImage(base, Math.floor(Math.random() * LR) - LR, 310 - 54 + Math.floor(Math.random() * LR) - LR, 256 + LR, 54 + LR); + GIF.addFrame(ctx); + }; + GIF.finish(); + return GIF.out.getData(); + } + + static async circle(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + image = await jimp.read(image); + image.circle(); + let raw; + image.getBuffer("image/png", (err, buffer) => { + raw = buffer; + }); + return raw; + } + + static async jail(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let bg = await Canvas.loadImage(__dirname +"/assets/jail.png"); + let img = await Canvas.loadImage(image); + const canvas = Canvas.createCanvas(400, 400); + const ctx = canvas.getContext("2d"); + ctx.drawImage(img, 0, 0, 400, 400); + ctx.drawImage(bg, 0, 0, 400, 400); + return canvas.toBuffer(); + } + + static async mms(image) { + if (!image) throw new Error("You must provide an image as a first argument."); + let bg = await Canvas.loadImage(__dirname +"/assets/mms.png"); + let img = await Canvas.loadImage(image); + const canvas = Canvas.createCanvas(400, 400); + const ctx = canvas.getContext("2d"); + ctx.drawImage(img, 70, 20, 250, 250); + ctx.drawImage(bg, 0, 0, 400, 400); + return canvas.toBuffer(); + } +} + +module.exports = DIG; diff --git a/src/module/assets/affect.png b/src/module/assets/affect.png new file mode 100644 index 0000000..161b21c Binary files /dev/null and b/src/module/assets/affect.png differ diff --git a/src/module/assets/batslap.png b/src/module/assets/batslap.png new file mode 100644 index 0000000..173478f Binary files /dev/null and b/src/module/assets/batslap.png differ diff --git a/src/module/assets/beautiful.png b/src/module/assets/beautiful.png new file mode 100644 index 0000000..146663c Binary files /dev/null and b/src/module/assets/beautiful.png differ diff --git a/src/module/assets/bed.png b/src/module/assets/bed.png new file mode 100644 index 0000000..4032e8f Binary files /dev/null and b/src/module/assets/bed.png differ diff --git a/src/module/assets/delete.png b/src/module/assets/delete.png new file mode 100644 index 0000000..bff094b Binary files /dev/null and b/src/module/assets/delete.png differ diff --git a/src/module/assets/facepalm.png b/src/module/assets/facepalm.png new file mode 100644 index 0000000..88545f9 Binary files /dev/null and b/src/module/assets/facepalm.png differ diff --git a/src/module/assets/gay.png b/src/module/assets/gay.png new file mode 100644 index 0000000..002f698 Binary files /dev/null and b/src/module/assets/gay.png differ diff --git a/src/module/assets/hitler.png b/src/module/assets/hitler.png new file mode 100644 index 0000000..28f495a Binary files /dev/null and b/src/module/assets/hitler.png differ diff --git a/src/module/assets/jail.png b/src/module/assets/jail.png new file mode 100644 index 0000000..149c204 Binary files /dev/null and b/src/module/assets/jail.png differ diff --git a/src/module/assets/kiss.png b/src/module/assets/kiss.png new file mode 100644 index 0000000..a3ecd1b Binary files /dev/null and b/src/module/assets/kiss.png differ diff --git a/src/module/assets/mms.png b/src/module/assets/mms.png new file mode 100644 index 0000000..4f34a56 Binary files /dev/null and b/src/module/assets/mms.png differ diff --git a/src/module/assets/rip.png b/src/module/assets/rip.png new file mode 100644 index 0000000..f5060e0 Binary files /dev/null and b/src/module/assets/rip.png differ diff --git a/src/module/assets/spank.png b/src/module/assets/spank.png new file mode 100644 index 0000000..1220893 Binary files /dev/null and b/src/module/assets/spank.png differ diff --git a/src/module/assets/trash.png b/src/module/assets/trash.png new file mode 100644 index 0000000..7baa957 Binary files /dev/null and b/src/module/assets/trash.png differ diff --git a/src/module/assets/triggered.png b/src/module/assets/triggered.png new file mode 100644 index 0000000..6e3010e Binary files /dev/null and b/src/module/assets/triggered.png differ diff --git a/src/module/assets/wanted.png b/src/module/assets/wanted.png new file mode 100644 index 0000000..0697b35 Binary files /dev/null and b/src/module/assets/wanted.png differ