Skip to content

Commit

Permalink
Add Write function
Browse files Browse the repository at this point in the history
Co-Authored-By: ForGetFulSkyBro <47897305+forgetfulskybro@users.noreply.github.com>
  • Loading branch information
mezotv and forgetfulskybro committed Jan 8, 2023
1 parent 097c498 commit 52bf323
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 78 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const Canvas = require("./src/Canvacord");
const Canva = require("./src/Canva");

module.exports = {
Canvas: Canvas,
Canvas: Canva,
Canva,
Spotify: require('./src/plugins/Spotify'),
write: Canva.write,
author: require("./package.json").author,
version: require("./package.json").version
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"author": "Dominik",
"license": "MIT",
"dependencies": {
"@napi-rs/canvas": "^0.1.32"
"@napi-rs/canvas": "0.1.30"
}
}
14 changes: 14 additions & 0 deletions src/Canva.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require("fs");

class Canva {
constructor() {
throw new Error(`The ${this.constructor.name} class may not be instantiated!`);
}

static write(data, name) {
return fs.writeFileSync(data, name);
}

}

module.exports = Canva;
26 changes: 9 additions & 17 deletions src/plugins/Spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,17 @@ class Spotify {
if (typeof this.albumArt !== "string") {
throw new TypeError("Spotify Album Art needs to be a string!");
}
}

// add a tiny async function

this.generate = async () => {
async build() {

console.log(albumArt)
const { song, artist, album, duration, albumArt } = this;

const color = await getSpotifyColor(albumArt)

if(isLight(color[0])) { color[0] = "#0F0F0F" }
if(isLight(color[1])) { color[1] = "#0F0F0F" }

console.log(color)
canvas.GlobalFonts.registerFromPath(join(__dirname, '..', '/', 'fonts', 'AvenirNextLTPro-Bold.otf'), 'FontBold')
canvas.GlobalFonts.registerFromPath(join(__dirname, '..', '/', 'fonts', 'AvenirNextLTPro-Regular.otf'), 'FontRegular')
const canvasObject = canvas.createCanvas(428, 926);
Expand All @@ -78,7 +76,7 @@ class Spotify {

// draw the album art image onto the canvas

const logo = canvas.loadImage(albumArt);
const logo = await canvas.loadImage(albumArt);
ctx.drawImage(logo, 26, 160, 380, 380);

ctx.font = '14px FontBold'
Expand Down Expand Up @@ -117,18 +115,12 @@ class Spotify {
ctx.textBaseline = "top"; // align the text to the top of the canvas
ctx.fillText("0:00", 20, 694)

const image = canvas.loadImage("https://cdn.discordapp.com/attachments/1047187283234795580/1053677610367975624/Track_View.png");
const image = await canvas.loadImage("https://cdn.discordapp.com/attachments/1047187283234795580/1053677610367975624/Track_View.png");
ctx.drawImage(image, 0, 0, 428, 926);
}
this.generate()

// returns the buffer
return canvasObject.encode("png");
}
}




const spotify = new Spotify("albumart", "song", "song", 12999, "https://cdn.discordapp.com/attachments/1007751044463345784/1053673397319630878/spotify-card.png");

module.exports = Spotify;

console.log(spotify);
module.exports = Spotify;
14 changes: 14 additions & 0 deletions test/Index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const canva = require("../index");

const spotify = new canva.Spotify(
"Kill Bill",
"SZA",
"SOS",
153946,
"https://i.scdn.co/image/ab67616d0000b27370dbc9f47669d120ad874ec1"
);

spotify.build().then((img) => {
canva.write("./test/spotifycard.png", img);
console.log(img)
});
Binary file added test/spotifycard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 58 additions & 58 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,62 @@
# yarn lockfile v1


"@napi-rs/canvas-android-arm64@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-0.1.32.tgz#003128ced4fe570c29a9601b88131c729dc9cb78"
integrity sha512-WvfDvaJCQlMA4eUZnAEmn6efrtyD7qraBK0pq4A+GQPKccFUO16lxnLlq/CKvlKmphYjxGN5CB+Gfd4ZKWEfzQ==

"@napi-rs/canvas-darwin-arm64@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-0.1.32.tgz#e24b13a327379c1b3c8677d0f1ece6ef65e8abaf"
integrity sha512-Fm6U9IcXHin6hipLyFlcEGyFFBhrjjjqdspmftNBSBl9hkJQPHtPjSboaT33YZBNH/2gfjiH36oBafr7ZR+Ozg==

"@napi-rs/canvas-darwin-x64@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-0.1.32.tgz#0fa2bb0c13406e7770bcbcc3626b5b212e37cd28"
integrity sha512-DMQl4VCuIQCoURWzkXQA82BELsmJjkghGbO/AOOUNrFjk03VBkEzwTVz/mHEuBV8QN6mGOMmfKeCIGYo/QE9yg==

"@napi-rs/canvas-linux-arm-gnueabihf@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-0.1.32.tgz#fbf9096a856a7ff4125c8ded2fc94772173525ea"
integrity sha512-eZ/g6i09AYI+t2eyJKSbPwPCan65NmHZONJxXU/t6BAptdVqq9FosrEwOcpBVldkU1IO4nLO5C7fCkOJQzKrBw==

"@napi-rs/canvas-linux-arm64-gnu@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-0.1.32.tgz#570d48b0a571ead116583ef32089f77672a058fb"
integrity sha512-q4cnQHMj/tjl/8nzxYcrbAgM4JB80xRD+Frfysv75D3SUBe+B1a3+YWHmWZVqLPiiavv0n9GcEoh1XdjFf/URw==

"@napi-rs/canvas-linux-arm64-musl@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-0.1.32.tgz#677c31a2ae39d2b8ac121ace6f41eeaaf6cac351"
integrity sha512-VOARylcuDcmIQpVO39xbnnzetPqubAh8s8GG/0frzhs8vERB5Wgh59cp5Nr23MKtdWLwzgzcVVyah4v4IopCYQ==

"@napi-rs/canvas-linux-x64-gnu@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-0.1.32.tgz#765cbdc4356fbbba9246b6e5f6af417d9fd0b8fc"
integrity sha512-G90Bdszk+U/7SlvrVSj2IXn87PHWTbLjTN2J+9hoyxU/b5lEr4Oe4aB0Cs3K5m6SVTvjf9GzRU0SceJzJlI/3g==

"@napi-rs/canvas-linux-x64-musl@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-0.1.32.tgz#db24fde1e49e1974d2747060bf80fb4d4fbb786a"
integrity sha512-ZDvqQA+z1CJbAhujOJT5qc9iwo1z9o3G7Rho8ZfzUwSvgyC0YqbCDM4tzf7iRQzg07caxRZq3kAnDrR/MgkGRg==

"@napi-rs/canvas-win32-x64-msvc@0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-0.1.32.tgz#fb02d2e80330d2a80a4c9a7a75fc915623e8d41a"
integrity sha512-WxI8EokD+hIlcw1DDXN+88u+vsBtAeuy08/7Z1JNSu8cLi59ogTy9bfXI2796hW3x8WSF51Bqd8SUJ9lluQUuA==

"@napi-rs/canvas@^0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas/-/canvas-0.1.32.tgz#13a23184f8a5aaadaf47ae2242726587b2bb2bcc"
integrity sha512-mStiUFKNL/Hs3FuD84lfnVlIoIWvQ60ubDoJ6FY0rFsXSYWSxp3KVXwVe+7e41rYxj6J7U2/vPL5bUoCWxO4bQ==
"@napi-rs/canvas-android-arm64@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-0.1.30.tgz#6fd18fda735e67044406a8abec30c325a66e572c"
integrity sha512-RaJvfg5x8QV+3WVqxwi1dt05mqiDuQF/w4wj8b6SHbxbVLfzZ5T0M9PFBTvjNU88GxiiVYUihxJeCCDs1sXP0g==

"@napi-rs/canvas-darwin-arm64@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-0.1.30.tgz#15425b5ceb1c7b33660aba1041a15d9fd51bff99"
integrity sha512-ZWW7+YYGFREzeV1uoGv0uUx+0OhGd5jQ6zFdaGYFESUjmLlfZ/LS0CG/IlbWDiWbnRPu2HQl0/TOQHurleJjLw==

"@napi-rs/canvas-darwin-x64@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-0.1.30.tgz#aef58dac52bb56af127e5560251e190d2c25e24b"
integrity sha512-DThro7Y3QFV/9bl/EORWXzBMXeIZU1jo80oI8Ha2Xsoy3Eq+wHhnlMyvNYcLjalxIFU/JJrzu6/qxjPaVzcw5A==

"@napi-rs/canvas-linux-arm-gnueabihf@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-0.1.30.tgz#9f114122792ed7fe517cb9ba28946453d693f47e"
integrity sha512-bMz85lH3y2JL7Xf8szu/EayyEffN2FSAUtxOm6U3/MLc7jW2Pt8TRhAQQxnv0zNh8ub7qBDky+LspMBPLTDRzA==

"@napi-rs/canvas-linux-arm64-gnu@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-0.1.30.tgz#dd5ec0cfd6235f81ead87d46d333181d3104f267"
integrity sha512-KHUVFOaG7wE4/GGTLk434GH7DIhPa7hhfMyzLqU1QFRXzjo0KIyO9gecHEF9snXaqvD4c/8YubEtFbWZVMSKUw==

"@napi-rs/canvas-linux-arm64-musl@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-0.1.30.tgz#156ed047575e3b6b64339507c665e3995421279b"
integrity sha512-9ckRCQbt/ZVNbHvApKhvaRM+mahMl4xryV0vUEKgFHo8Fm4j56dPZRWeKojmk1vSGC9ahY73K1MEb0OaIxOv0Q==

"@napi-rs/canvas-linux-x64-gnu@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-0.1.30.tgz#e4d28c6c28745428a88514e2f921f214d370fbf5"
integrity sha512-NSyhCClsTBs06ViivDU0lSGVTDBBtm3pSTQKZseAnBEEF0vuO4De5SJl4JYng9eSDQ6KqA4TkOZFUMxokP6ZVg==

"@napi-rs/canvas-linux-x64-musl@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-0.1.30.tgz#d4d7f6832180c66f36b991b3de2b5cbdc1d4cc25"
integrity sha512-hT3sPij6nHKiH10avrd8MNwLYEBzwiVyzA0nxPosGJ+ErWk1tgE4UeM3w1+BWYK3S/wgY/4WlhxDgsd9crUGRA==

"@napi-rs/canvas-win32-x64-msvc@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-0.1.30.tgz#c92f9a1c757dd2f059bbca9b0a269269a8fe2a86"
integrity sha512-6MwkIMd53jNqO+KAvv2A7TtMY1MYE51VCdF7sZ61sypgjB/dOYmYqDgAU/RTHS5agyc0CZUeXoaZT43Lkgk67A==

"@napi-rs/canvas@0.1.30":
version "0.1.30"
resolved "https://registry.yarnpkg.com/@napi-rs/canvas/-/canvas-0.1.30.tgz#d18e0780f2bd59c7a859aa539a376a1bf638e065"
integrity sha512-XRR6PumJW9GdODD+HFW7ZKmpq7FE6PIKWn7QTcsJUdGNb54fTS1Z47oPFZ3pbvs07Xs8ZnkR03Q/9T3LfkGRgg==
optionalDependencies:
"@napi-rs/canvas-android-arm64" "0.1.32"
"@napi-rs/canvas-darwin-arm64" "0.1.32"
"@napi-rs/canvas-darwin-x64" "0.1.32"
"@napi-rs/canvas-linux-arm-gnueabihf" "0.1.32"
"@napi-rs/canvas-linux-arm64-gnu" "0.1.32"
"@napi-rs/canvas-linux-arm64-musl" "0.1.32"
"@napi-rs/canvas-linux-x64-gnu" "0.1.32"
"@napi-rs/canvas-linux-x64-musl" "0.1.32"
"@napi-rs/canvas-win32-x64-msvc" "0.1.32"
"@napi-rs/canvas-android-arm64" "0.1.30"
"@napi-rs/canvas-darwin-arm64" "0.1.30"
"@napi-rs/canvas-darwin-x64" "0.1.30"
"@napi-rs/canvas-linux-arm-gnueabihf" "0.1.30"
"@napi-rs/canvas-linux-arm64-gnu" "0.1.30"
"@napi-rs/canvas-linux-arm64-musl" "0.1.30"
"@napi-rs/canvas-linux-x64-gnu" "0.1.30"
"@napi-rs/canvas-linux-x64-musl" "0.1.30"
"@napi-rs/canvas-win32-x64-msvc" "0.1.30"

0 comments on commit 52bf323

Please sign in to comment.