Socket
Socket
Sign inDemoInstall

random-stuff-api

Package Overview
Dependencies
200
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.5.0 to 9.0.0

151

index.js

@@ -7,2 +7,4 @@ const giveMeAJoke = require("discord-jokes");

const Canvacord = require('canvacord')
const Canvas = require('canvas')
const fs = require('fs')
process

@@ -188,13 +190,148 @@ .on('unhandledRejection', (reason, p) => {

canva: {
triggered: async (string) => {
Canvacord.Canvas.trigger(string)
/**
* Delete
* @param {string|Buffer} image Source image
* @param {boolean} dark If image should be in dark mode
* @returns {Promise<Buffer>}
*/
delete: async (image, dark = false) => {
if (!image) throw new Error("image was not provided!");
await this.__wait();
const img = await Canvas.loadImage(image);
const bg = await Canvas.loadImage(dark ? await Canvacord.invert(Canvacord.assets("IMAGE").DELETE) : Canvacord.assets("IMAGE").DELETE);
const canvas = Canvas.createCanvas(bg.width, bg.height);
const ctx = canvas.getContext("2d");
ctx.drawImage(bg, 0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 120, 135, 195, 195);
return canvas.toBuffer();
},
delete: async (string) => {
Canvacord.Canvas.delete(string)
/**
* Blur an image
* @param {string|Buffer} image Image to blur
* @returns {Promise<Buffer>}
*/
blur: async (image) => {
if (!image) throw new Error("Image was not provided!");
const img = await Canvas.loadImage(image);
const canvas = Canvas.createCanvas(img.width, img.height);
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#ffffff";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 0, 0, canvas.width / 4, canvas.height / 4);
ctx.imageSmoothingEnabled = true;
ctx.drawImage(canvas, 0, 0, canvas.width / 4, canvas.height / 4, 0, 0, canvas.width + 5, canvas.height + 5);
return canvas.toBuffer();
},
/**
* Writes the data as file
* @param {Buffer} data data to write
* @param {string} name file name
* @returns {void}
*/
write: async (data , name) => {
return fs.writeFileSync(name, data);
},
blur: async (string) => {
Canvacord.Canvas.blur(string)
}
/**
* Pixelate
* @param {string|Buffer} image Image to pixelate
* @param {number} pixels Pixels
* @returns {Promise<Buffer>}
*/
pixelate: async (image , pixels = 5) => {
if (!image) throw new Error("Image was not provided!");
if (!pixels || typeof pixels !== "number") pixels = 100;
if (pixels < 1) pixels = 100;
if (pixels > 100) pixels = 100;
const img = await Canvas.loadImage(image);
const canvas = Canvas.createCanvas(img.width, img.height);
const ctx = canvas.getContext("2d");
const pixel = pixels / 100;
ctx.drawImage(img, 0, 0, canvas.width * pixel, canvas.height * pixel);
ctx.imageSmoothingEnabled = false;
ctx.drawImage(canvas, 0, 0, canvas.width * pixel, canvas.height * pixel, 0, 0, canvas.width + 5, canvas.height + 5);
return canvas.toBuffer();
},
/**
* Sharpen an image
* @param {string|Buffer} image Image to sharpen
* @param {number} lvl sharpness intensity
* @returns {Promise<Buffer>}
*/
sharp: async (image , lvl = 1) => {
if (!image) throw new Error("Image was not provided!");
return await Convolute(image, Canvacord.CONVOLUTION_MATRIX.SHARPEN, true, lvl);
},
/**
* Applies burn effect on an image
* @param {string|Buffer} image Image source
* @param {number} lvl intensity
* @returns {Promise<Buffer>}
*/
burn: async (image , lvl = 1) => {
if (!image) throw new Error("Image was not provided!");
return await Convolute(image, Canvacord.CONVOLUTION_MATRIX.BURN, true, lvl);
},
/**
* Creates circular image
* @param {string|Buffer} image Image source
* @returns {Promise<Buffer>}
*/
circle: async (image) => {
if (!image) throw new Error("Image was not provided!");
const img = await Canvas.loadImage(image);
const canvas = Canvas.createCanvas(img.width, img.height);
const ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
circle(ctx, canvas.width, canvas.height);
return canvas.toBuffer();
},
/**
* facepalm
* @param {string|Buffer} image image
* @returns {Promise<Buffer>}
*/
facepalm: async (image) => {
if (!image) throw new Error("image was not provided!");
await this.__wait();
let layer = await Canvas.loadImage(Canvacord.assets("IMAGE").FACEPALM);
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);
ctx.drawImage(layer, 0, 0, 632, 357);
return canvas.toBuffer();
},
/**
* Rainbow ( ͡° ͜ʖ ͡°)
* @param {string|Buffer} image Image source
* @returns {Promise<Buffer>}
*/
rainbow: async (image) => {
if (!image) throw new Error("image was not provided!");
await this.__wait();
let bg = await Canvas.loadImage(Canvacord.assets("IMAGE").GAY);
let img = await Canvas.loadImage(image);
const canvas = Canvas.createCanvas(img.width, img.height);
const ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
ctx.drawImage(bg, 0, 0, canvas.width, canvas.height);
return canvas.toBuffer();
},
}
}

4

package.json
{
"name": "random-stuff-api",
"version": "8.5.0",
"version": "9.0.0",
"description": "Random Jokes , memes , aww moments , devjokes , cat/dog/duck/horse etc images and videos , hp memes and many more ",

@@ -27,3 +27,3 @@ "main": "index.js",

},
"homepage": "https://github.com/pgamerxstudio/random-stuff-api",
"homepage": "https://random-stuff-api.js.org/",
"keywords": [

@@ -30,0 +30,0 @@ "random",

@@ -31,12 +31,9 @@ # Random-stuff-api

## Recent Changes
### Version 8.5.x
Added Classes!
* Now the api has been made arranged into classes
* There are currently 2 classes -
* random // used for functions which has a random response as output (for eg - joke , insult)
* image // Used for functions which has image as an output (for eg - dog , cat)
* Added Image manipulation (it may not work)
* For eg - api.canva.blur("image url")
* For eg - Now to get a joke you will do api.random.joke()
**Scroll down for all functions explained**
### Version 9.x
Added -
* `api.canva.rainbow // rainbow effect`
* `api.canva.circle // provides circular version of image`
* `api.canva.sharp // sharpens the image`
* `api.canva.burn // burn effect on image`
* `api.canva.pixelate // pixelates the image`

@@ -49,5 +46,6 @@ ## Declaration

## Classes
Currently there are currently 2 classes -
Currently there are currently 3 classes -
* random // used for functions which has a random response as output (for eg - joke , insult)
* image // Used for functions which has image as an output (for eg - dog , cat)
* canva // for image manipulation and has only 3 functions atm
**(Scroll down for all functions and example)**

@@ -67,7 +65,8 @@

const image = "img url"
api.canva.blur(image).then(buffer => {
// Do anything with buffer
// For eg = new Discord.MessageAttachment(buffer, "blur.png");
})
const image = getimagesomehow()
api.canva.pixelate(image)
.then(buffer => {
api.canva.write(buffer, "./pixelate.png");
})
.catch(console.error);
```

@@ -79,3 +78,9 @@

* `api.canva.delete() // the delete memey thingy`
* `api.canva.triggered() // the triggered gif`
* `api.canva.rainbow // rainbow effect`
* `api.canva.circle // provides circular version of image`
* `api.canva.sharp // sharpens the image`
* `api.canva.burn // burn effect on image`
* `api.canva.pixelate // pixelates the image`
* `api.canva.write() // to save The image`
### Class random

@@ -82,0 +87,0 @@ * `api.random.joke() // Returns a dad joke`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc