Merge pull request #6 from ArcaneDisgea/clean-up
This commit is contained in:
commit
95f6bc1873
6 changed files with 49 additions and 23 deletions
|
@ -1,2 +1 @@
|
|||
index.js
|
||||
test.js
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const fetch = require("node-fetch");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { createCanvas, loadImage, registerFont } = require("canvas");
|
||||
|
||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "shit",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
{
|
||||
"name": "xiv-character-cards",
|
||||
"version": "1.0.0",
|
||||
"description": "API to create fancy cards for FFXIV characters based on their Lodestone data, hosted at https://ffxiv-character-cards.herokuapp.com.",
|
||||
"version": "1.1.0",
|
||||
"main": "create-card.js",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"ffxiv",
|
||||
"xivapi"
|
||||
],
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"dev": "nodemon index.js"
|
||||
|
|
43
readme.md
43
readme.md
|
@ -32,4 +32,45 @@ The API will reply with its status, and in case of success, the URL to the final
|
|||
|
||||
## Using in your application
|
||||
|
||||
You can use the ``create-card.js`` file in any NodeJS project. It will return a PNG-buffer for you to use in your bot or application.<br>Check ``index.js`` for usage examples.
|
||||
```
|
||||
yarn add xiv-character-cards
|
||||
# or
|
||||
npm i xiv-character-cards
|
||||
```
|
||||
|
||||
You will receive a PNG-buffer for you to use in your bot or application.<br>Check ``index.js`` for other usage examples.
|
||||
|
||||
### Example
|
||||
|
||||
```js
|
||||
const { CardCreator } = require("xiv-character-cards");
|
||||
const fs = require("fs");
|
||||
|
||||
const card = new CardCreator();
|
||||
const lodestoneid = "13821878";
|
||||
|
||||
function example(cb) {
|
||||
card.ensureInit()
|
||||
.then(
|
||||
() => card.createCard(lodestoneid),
|
||||
(reason) => cb("Init failed: " + reason, null)
|
||||
)
|
||||
.then((image) =>
|
||||
cb(null, {
|
||||
binary: {
|
||||
image: image,
|
||||
},
|
||||
})
|
||||
)
|
||||
.catch((reason) => cb("createCard failed: " + reason, null));
|
||||
}
|
||||
|
||||
example((err, response) => {
|
||||
const buffer = response.binary.image;
|
||||
fs.writeFileSync(`./${lodestoneid}.png`, response.binary.image, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
|
18
test.js
18
test.js
|
@ -1,18 +0,0 @@
|
|||
const fs = require("fs");
|
||||
const createCard = require("./create-card").createCard;
|
||||
|
||||
createCard("9575452", (png) => {
|
||||
const data = png.replace(/^data:image\/\w+;base64,/, "");
|
||||
const buf = Buffer.from(data, "base64");
|
||||
fs.writeFile('test.png', buf, (err) => {
|
||||
console.log(err)
|
||||
})
|
||||
});
|
||||
|
||||
createCard("13821878", (png) => {
|
||||
const data = png.replace(/^data:image\/\w+;base64,/, "");
|
||||
const buf = Buffer.from(data, "base64");
|
||||
fs.writeFile('image.png', buf, (err) => {
|
||||
console.log(err)
|
||||
})
|
||||
});
|
Loading…
Reference in a new issue