instant-meme
Advanced tools
Comparing version 2.3.2 to 2.4.0
@@ -25,2 +25,3 @@ const { createCanvas, loadImage, registerFont } = require('canvas') | ||
//write the lines | ||
if(lines[0].length = 0) lines.shift; | ||
for(let index in lines){ | ||
@@ -33,2 +34,25 @@ let line = lines[index].trim(); | ||
/** Writes watermark to canvas, iff env variable INSTANT_MEME_WATERMARK | ||
* | ||
* @param {CanvasRenderingContext2D} context Canvase contex to be written to. | ||
* @param {String} font_family Name of the font to use when writing watermark. | ||
*/ | ||
function addWatermark(context) { | ||
const watermark = process.env.INSTANT_MEME_WATERMARK; | ||
if(!watermark) return; | ||
//get half size font. | ||
const font_original = context.font; | ||
const font_half_height = Number(font_original.replace(/\D/g,''))/2; | ||
const font_half = font_half_height + font_original.replace(/^\d+/,''); | ||
//get text postion | ||
context.font = font_half; | ||
const measurements = context.measureText(watermark); | ||
const x = context.canvas.width - (measurements.width+5); | ||
const y = context.canvas.height - (font_half_height); | ||
//writing | ||
context.fillText(watermark,x,y); | ||
//cleanup | ||
context.font = font_original; | ||
} | ||
/** | ||
@@ -45,3 +69,3 @@ * | ||
const ctx = canvas.getContext('2d'); | ||
ctx.font = `${templateData.font_size} "daFont"`; | ||
ctx.font = `${templateData.font_size} daFont`; | ||
ctx.drawImage(image,0,0); | ||
@@ -52,4 +76,4 @@ for(textData of Object.values(templateData.texts)) { | ||
wraptext(ctx,text,x,y,maxwidth,templateData.font_size); | ||
// ctx.fillText(text,x,y,maxwidth); | ||
} | ||
addWatermark(ctx); | ||
return canvas.toBuffer(); | ||
@@ -56,0 +80,0 @@ } |
{ | ||
"name": "instant-meme", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"description": "A express middleware to build 'memes' on the fly by specifying the image and text content in the url. Because photoshop is to slow for conversation.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,2 +23,6 @@ # Instant Meme | ||
#### Optional Environmental Variables | ||
- INSTANT_MEME_WATERMARK : string, if set, will add a watermark to the lower right hand corner of the image. | ||
#### Create Assets Directory | ||
@@ -25,0 +29,0 @@ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
10420
150
104
2