canvacord
Advanced tools
Comparing version 2.0.5 to 2.0.6
{ | ||
"name": "canvacord", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Simple & easy to use image manipulation module.", | ||
@@ -11,2 +11,3 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://canvacord.snowflakedev.cf", | ||
"repository": { | ||
@@ -13,0 +14,0 @@ "type": "git", |
@@ -42,5 +42,7 @@ # Canvacord | ||
- leaver({ username, discrim, avatarURL }) | ||
- rank({ username, discrim, level, rank, neededXP, currentXP, avatarURL }) | ||
- rank({ username, discrim, level, rank, neededXP, currentXP, avatarURL, color, background }) | ||
- read(ImageOrBuffer) | ||
- pixelate(image, level) | ||
- write(buffer, filename) | ||
- jokeoverthehead(image) | ||
@@ -92,2 +94,18 @@ # Example | ||
} | ||
if (message.content === "!rank") { | ||
let rank = getRankSomehow(); | ||
let image = await canva.rank({ | ||
username, | ||
discrim, | ||
level, | ||
rank, | ||
neededXP, | ||
currentXP, | ||
avatarURL, | ||
color, | ||
background | ||
}); | ||
let attachment = new Discord.MessageAttachment(image, "rank.png"); | ||
return message.channel.send(attachment); | ||
} | ||
}); | ||
@@ -99,6 +117,12 @@ | ||
# Documentation | ||
**[https://canvacord.snowflakedev.cf](https://canvacord.snowflakedev.cf)** | ||
# Preview | ||
![image](https://raw.githubusercontent.com/Snowflake107/canvacord/master/screenshot.png) | ||
# Rank Card | ||
![rankCard](https://media.discordapp.net/attachments/715806802670780436/723768235714936832/rank.png) | ||
# Join Our Discord Server | ||
**[discord.gg/uqB8kxh](https://discord.gg/uqB8kxh)** |
/** | ||
* Initial Release - 7 March 2020 | ||
* @author Snowflake107, Zyrouge | ||
* @author Snowflake107 | ||
* @license Apache License 2.0 | ||
@@ -34,3 +34,3 @@ * xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
* @example const Canvacord = require("canvacord"); | ||
* const canva = new Canvacord.Canvas(); | ||
* const canva = new Canvacord(); | ||
*/ | ||
@@ -64,2 +64,3 @@ constructor() { | ||
'jail', | ||
'jokeoverthehead', | ||
'kiss', | ||
@@ -71,2 +72,3 @@ 'leave', | ||
'rankCard', | ||
'read', | ||
'rip', | ||
@@ -89,3 +91,3 @@ 'sepia', | ||
* @param {Image2} image2 second image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.batslap(img, img1); | ||
@@ -112,3 +114,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.beautiful(img); | ||
@@ -132,3 +134,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.facepalm(img); | ||
@@ -153,3 +155,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.gay(img); | ||
@@ -173,3 +175,3 @@ * canva.write(img, "img.png"); | ||
* @param {image2} image2 second image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.kiss(img); | ||
@@ -195,3 +197,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.rip(img); | ||
@@ -215,3 +217,3 @@ * canva.write(img, "img.png"); | ||
* @param {image2} image2 second image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.spank(img, img1); | ||
@@ -238,3 +240,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.trash(img); | ||
@@ -258,3 +260,3 @@ * canva.write(img, "img.png"); | ||
* @param {Number} level blur level | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.blur(img); | ||
@@ -274,3 +276,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.greyscale(img); | ||
@@ -290,3 +292,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.sepia(img); | ||
@@ -306,3 +308,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.invert(img); | ||
@@ -322,3 +324,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.delete(img); | ||
@@ -340,3 +342,3 @@ * canva.write(img, "img.png"); | ||
* @param {Color} color name/hex | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.color("#FF0000"); | ||
@@ -359,2 +361,4 @@ * canva.write(img, "img.png"); | ||
* console.log(color); | ||
* @private | ||
* @ignore | ||
*/ | ||
@@ -374,3 +378,3 @@ _getHex(color) { | ||
* @param {Image} image image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.trigger(img); | ||
@@ -420,3 +424,3 @@ * canva.write(img, "img.gif"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.hitler(img); | ||
@@ -439,3 +443,3 @@ * canva.write(img, "img.png"); | ||
* @param {image2} image2 second image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.bed(img, img1); | ||
@@ -464,3 +468,3 @@ * canva.write(img, "img.png"); | ||
* @param {image} Image image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.wanted(img); | ||
@@ -482,3 +486,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.circle(img); | ||
@@ -490,2 +494,3 @@ * canva.write(img, "img.png"); | ||
image = await jimp.read(image); | ||
image.resize(1024, 1024); | ||
image.circle(); | ||
@@ -499,3 +504,3 @@ let raw = await image.getBufferAsync('image/png'); | ||
* @param {image} Image image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.jail(img); | ||
@@ -520,3 +525,3 @@ * canva.write(img, "img.png"); | ||
* @param {image} Image image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.affect(img); | ||
@@ -538,3 +543,3 @@ * canva.write(img, "img.png"); | ||
* @param {Image} image Image | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.dither(img); | ||
@@ -553,4 +558,4 @@ * canva.write(img, "img.png"); | ||
* wasted | ||
* @param {{Buffer}} Image Image to manipulate | ||
* @returns {Buffer} | ||
* @param {Buffer} Image Image to manipulate | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.wasted(img); | ||
@@ -571,2 +576,13 @@ * canva.write(img, "img.png"); | ||
/** | ||
* Reads the image | ||
* @param {Buffer|String} image buffer or string to read image from. | ||
* @returns {Promise<Buffer>} | ||
*/ | ||
async read(image) { | ||
if (!image) throw new Error('No image provided!'); | ||
let i = await Canvas.loadImage(image); | ||
return i; | ||
} | ||
/** | ||
* rank | ||
@@ -579,9 +595,10 @@ * @param {String} username Username | ||
* @param {String} currentXP Current XP of a user | ||
* @param {{Buffer}} avatarURL Avatar URL or {Buffer} or Canvacord {Buffer} itself | ||
* @param {Buffer|String} avatarURL Avatar URL or {Buffer} or Canvacord {Buffer} itself | ||
* @param {String} color Hex or HTML5 color name or rgb | ||
* @returns {Buffer} | ||
* @param {String|Buffer} background Rank card background image | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.rank({ username: "Snowflake", discrim: "0007", level: 4, rank: 12, neededXP: 500, currentXP: 407, avatarURL: "...", color: "#FFFFFF" }); | ||
* canva.write(img, "img.png"); | ||
*/ | ||
async rank({ username, discrim, level, rank, neededXP, currentXP, avatarURL, color }) { | ||
async rank({ username, discrim, level, rank, neededXP, currentXP, avatarURL, color, background }) { | ||
if (!username) throw new Error('No username was provided!'); | ||
@@ -605,7 +622,30 @@ if (!level) throw new Error('No level was provided!'); | ||
}); | ||
const convert = (num) => { | ||
if (!num) return NaN; | ||
if (typeof num === 'string') num = parseInt(num); | ||
let decPlaces = Math.pow(10, 1); | ||
var abbrev = ['K', 'M', 'B', 'T']; | ||
for (var i = abbrev.length - 1; i >= 0; i--) { | ||
var size = Math.pow(10, (i + 1) * 3); | ||
if (size <= num) { | ||
num = Math.round((num * decPlaces) / size) / decPlaces; | ||
if (num == 1000 && i < abbrev.length - 1) { | ||
num = 1; | ||
i++; | ||
} | ||
num += abbrev[i]; | ||
break; | ||
} | ||
} | ||
return num; | ||
}; | ||
const canvas = Canvas.createCanvas(934, 282); | ||
const ctx = canvas.getContext('2d'); | ||
const rankCard = await Canvas.loadImage(__dirname + '/assets/rankcard.png'); | ||
let bg; | ||
let rankCard; | ||
if (typeof background === 'string' || Buffer.isBuffer(background)) { | ||
bg = await Canvas.loadImage(background); | ||
ctx.drawImage(bg, 0, 0, canvas.width, canvas.height); | ||
rankCard = await Canvas.loadImage(__dirname + '/assets/rankcard2.png'); | ||
} else rankCard = await Canvas.loadImage(__dirname + '/assets/rankcard.png'); | ||
ctx.drawImage(rankCard, 0, 0, canvas.width, canvas.height); | ||
@@ -616,5 +656,5 @@ | ||
ctx.font = `bold 36px ${font}`; | ||
ctx.fillStyle = '#FFFFFF'; | ||
ctx.fillStyle = color; | ||
ctx.textAlign = 'start'; | ||
const name = username >= 7 ? username.substring(0, 7).trim() + '...' : username; | ||
const name = username.length >= 10 ? username.substring(0, 70).trim() + '...' : username; | ||
ctx.fillText(`${name}`, 264, 164); | ||
@@ -624,3 +664,3 @@ ctx.font = `36px ${font}`; | ||
ctx.textAlign = 'center'; | ||
if (discrim) ctx.fillText(`#${discrim}`, ctx.measureText(name).width + 10 + 316, 164); | ||
if (discrim) ctx.fillText(`#${discrim}`, ctx.measureText(name).width + 10 + 335, 164); | ||
@@ -635,3 +675,3 @@ ctx.font = `bold 36px ${font}`; | ||
ctx.font = `bold 36px ${font}`; | ||
ctx.fillStyle = '#FFFFFF'; | ||
ctx.fillStyle = color; | ||
ctx.textAlign = 'end'; | ||
@@ -656,5 +696,5 @@ ctx.fillText(rank, 934 - 64 - ctx.measureText(level).width - 16 - ctx.measureText(`LEVEL`).width - 16, 82); | ||
ctx.textAlign = 'start'; | ||
ctx.fillText('/ ' + neededXP, 624 + ctx.measureText(currentXP).width + 10, 164); | ||
ctx.fillStyle = '#ffffff'; | ||
ctx.fillText(currentXP, 624, 164); | ||
ctx.fillText('/ ' + convert(neededXP), 670 + ctx.measureText(convert(currentXP)).width + 15, 164); | ||
ctx.fillStyle = color; | ||
ctx.fillText(convert(currentXP), 670, 164); | ||
@@ -694,6 +734,7 @@ let widthXP = (currentXP * 615) / neededXP; | ||
* @param {String} currentXP Current XP of a user | ||
* @param {{Buffer}} avatarURL Avatar URL or {Buffer} or Canvacord {Buffer} itself | ||
* @param {Buffer|String} avatarURL Avatar URL or {Buffer} or Canvacord {Buffer} itself | ||
* @param {String} color Hex or HTML5 color name or rgb | ||
* @returns {Buffer} | ||
* @example let img = await canva.rankCard({ username: "Snowflake", discrim: "0007", level: 4, rank: 12, neededXP: 500, currentXP: 407, avatarURL: "...", color: "#FFFFFF" }); | ||
* @param {String|Buffer} background Rank card background image | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.rank({ username: "Snowflake", discrim: "0007", level: 4, rank: 12, neededXP: 500, currentXP: 407, avatarURL: "...", color: "#FFFFFF" }); | ||
* canva.write(img, "img.png"); | ||
@@ -711,3 +752,3 @@ */ | ||
* @param {String} color Hex or HTML5 color name or rgb | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.welcome({ username: "Snowflake", discrim: "0007", avatarURL: "..." }); | ||
@@ -787,3 +828,3 @@ * canva.write(img, "img.png"); | ||
* @param {String} color Hex or HTML5 color name or rgb | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.welcomer({ username: "Snowflake", discrim: "0007", avatarURL: "..." }); | ||
@@ -802,3 +843,3 @@ * canva.write(img, "img.png"); | ||
* @param {String} color Hex or HTML5 color name or rgb | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.leaver({ username: "Snowflake", discrim: "0007", avatarURL: "..." }); | ||
@@ -878,3 +919,3 @@ * canva.write(img, "img.png"); | ||
* @param {String} color Hex or HTML5 color name or rgb | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.leave({ username: "Snowflake", discrim: "0007", avatarURL: "..." }); | ||
@@ -891,3 +932,3 @@ * canva.write(img, "img.png"); | ||
* @param {Number} level pixelation level | ||
* @returns {Buffer} | ||
* @returns {Promise<Buffer>} | ||
* @example let img = await canva.pixelate({ username: "Snowflake", discrim: "0007", avatarURL: "..." }); | ||
@@ -916,4 +957,22 @@ * canva.write(img, "img.png"); | ||
} | ||
/** | ||
* JokeOverTheHead | ||
* @param {String|Buffer} image Image to manipulate | ||
* @returns {Promise<Buffer>} | ||
*/ | ||
async jokeoverhead(image) { | ||
if (!image) throw new Error('no image provided!'); | ||
let canvas = Canvas.createCanvas(425, 404); | ||
let ctx = canvas.getContext('2d'); | ||
ctx.fillStyle = 'black'; | ||
ctx.fillRect(0, 0, 425, 404); | ||
image = await Canvas.loadImage(await this.circle(image)); | ||
ctx.drawImage(image, 125, 130, 140, 135); | ||
let layer = await Canvas.loadImage(__dirname + '/assets/jokeoverhead.png'); | ||
ctx.drawImage(layer, 0, 0, 425, 404); | ||
return canvas.toBuffer(); | ||
} | ||
} | ||
module.exports = Canvacord; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
2805629
27
861
126