Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
new Jimp(128, 128, function(err, spriteImage) {
Jimp.loadFont(path.join(__dirname, 'font.fnt')).then(function(font) {
spriteImage.rgba(false);
spriteImage.background(Jimp.rgbaToInt(0, 0, 0, 255));
var spriteDuplicateMap = {}
// Do an initial loop through our sprites to find ones with the same id + palette, so we can mark them.
for (var i = 0; i < parsedSpriteData.length; i++) {
var lookupId = parsedSpriteData[i].tileId + '_' + parsedSpriteData[i].palette;
if (!spriteDuplicateMap[lookupId]) {
spriteDuplicateMap[lookupId] = {totalCount: 1, thisCount: 0};
} else {
spriteDuplicateMap[lookupId].totalCount++;
}
}
// Okay, we're going to compose this image of sprites until we run out.
// All are 16x16, and we want to tile left to right, top to bottom
async function createCover() {
// load font and our base cover image
// we put subreddit into this image
const font = await Jimp.loadFont(Jimp.FONT_SANS_64_BLACK);
const image = await Jimp.read("./cover/Reddit2Ebook.jpg");
await image.print(
font,
0, // x
600, // y
{
text: subreddit,
alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
},
782, // maxWidth (use same width as base cover image to center correctly)
200 // maxHeight
)
.quality(80) // set JPEG quality. We don't need very high quality output.
.write("./cover/cover.jpg");
var image = new Jimp(400, 300, function (err, image) {
image.rgba(false);
console.log("generating image");
//Jimp.loadFont(Jimp.FONT_SANS_128_BLACK, function (err, font) {
var fontPath = path.join(__dirname, "font-hel.fnt");
Jimp.loadFont(fontPath, function (err, font) {
image.print(font, 20, 100, time_string);
image.getBase64( Jimp.MIME_PNG, function (err, base64) {
console.log(err);
console.log(base64);
resolve({ "message": "created text", "base64_data": base64 });
});
});
})
const writeText = async (
image,
{ text, font, color, size, style, x, y, xBounds, yBounds }
) => {
const filename = [font, color, style, size].join("_");
const fontFile = await Jimp.loadFont(
path.join(__dirname, `fonts/${filename}.fnt`)
);
return image.print(fontFile, x, y, { text }, xBounds, yBounds);
};