Last active
July 8, 2018 23:14
-
-
Save krisppurg/ec7940b4c7ac85f3c51a264a66733f21 to your computer and use it in GitHub Desktop.
Add an image to a Jesus meme using canvas-constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Canvas } = require("canvas-constructor"); // Import the Canvas thing from the 'canvas-constructor'. | |
const snekfetch = require("snekfetch") // Create a variable called 'snekfetch' that imports the snekfetch package aka the http request to get the image buffer. | |
function jesus(glob) { | |
// Get the jesus image | |
return snekfetch.get("https://cdn.discordapp.com/attachments/411126540131106816/465197193163440128/jesus.jpeg").then(res => { | |
const image = new Canvas(900, 756) | |
.addImage(res.body, 0, 0, 900, 756) // Adds the jesus image with x, y, width height | |
.addImage(glob, 420, 410, 500, 340) // adds the glob image with x, y, width height | |
.toBuffer() | |
return image // Return a value of the code above ('image') | |
}) | |
} | |
// Get the glob image | |
snekfetch.get("https://i.kym-cdn.com/entries/icons/original/000/025/620/1520460233746.jpg").then(resp => { | |
const glob = new Canvas(1280, 720) // Create a Canvas with the image resolution which is 720p | |
.changeCanvasSize(900, 756) // Change the size | |
.addImage(resp.body, 0, 0, 900, 756) // Add the glob image. | |
.toBuffer() // Make it to a Buffer | |
// Pass the glob variable to the jesus function | |
jesus(glob).then(jesus => { | |
console.log("data:image/png;base64," + Buffer.from(jesus).toString('base64')) // Log a base 64 url (https://en.wikipedia.org/wiki/Base64) on Command Prompt | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment