Skip to content

Instantly share code, notes, and snippets.

@edqx
Created April 18, 2020 15:24
Show Gist options
  • Save edqx/fcabb550cffcef5ae3bfdc5c19a051cc to your computer and use it in GitHub Desktop.
Save edqx/fcabb550cffcef5ae3bfdc5c19a051cc to your computer and use it in GitHub Desktop.
function EnlargeImage(message) {
const scale = parseInt((message.arguments.scale || "x4").match(/[1-8]/g)[0])
var url;
if (message.attachments.first()) {
if (message.attachments.first().url) {
url = message.attachments.first().url;
}
} else {
if (message.arguments.url !== null) {
url = message.arguments.url;
}
}
if (url) {
jimp.read(url).then(function (image) {
var ran_code = Math.random().toString(36).substr(2, 7);
image.resize(image.bitmap.width * scale, image.bitmap.height * scale)
.write(path.resolve(__dirname, "../info/img-temp/" + ran_code + ".png"), function (err, written) {
if (err) {
const reply_err_read = new discord.RichEmbed()
.setTitle("Enlarge Image :frame_photo:")
.setDescription("An error occurred while trying to write the image.")
.setColor(0xe0552b)
.setFooter("v" + C_VERSION + " by weak eyes#6969", "")
.setTimestamp();
message.channel.send(reply_err_read);
return console.log(err);
}
message.channel.send(new discord.Attachment(fs.createReadStream(path.resolve(__dirname, "../info/img-temp/" + ran_code + ".png")), ran_code + ".png"));
fs.unlink(path.resolve(__dirname, "../info/img-temp/" + ran_code + ".png"), function (err) {
if (err) {
console.log(err);
}
});
});
}).catch(function (err) {
console.log(err);
const reply_err_write = new discord.RichEmbed()
.setTitle("Enlarge Image :frame_photo:")
.setDescription("An error occurred while trying to read the image.")
.setColor(0xe0552b)
.setFooter("v" + C_VERSION + " by weak eyes#6969", "")
.setTimestamp();
message.channel.send(reply_err_write);
});
} else {
const reply_no_image = new discord.RichEmbed()
.setTitle("Enlarge Image :frame_photo:")
.setDescription("Please provide a URL or image attachment to enlarge.")
.setColor(0xe0552b)
.setFooter("v" + C_VERSION + " by weak eyes#6969", "")
.setTimestamp();
message.channel.send(reply_no_image);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment