Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
topText = topText || "";
botText = botText || "";
meme = meme.replace(/&/g, "").trim();
// sometimes, empty string does not clear the default
// "TOP TEXT" and "BOTTOM TEXT" from apimeme, so use space
topText = topText.replace(/&/g, "").trim() || "+";
botText = botText.replace(/&/g, "").trim() || "+";
meme = encodeURI(meme);
topText = encodeURI(topText);
botText = encodeURI(botText);
const uri = `http://apimeme.com/meme?meme=${meme}&top=${topText}&bottom=${botText}`;
base64.encode(uri, { filename: "meme.jpg" }, (error, image) => {
if(!error) {
msg.channel.createMessage("", {
file: image,
name: "meme.jpg"
});
}
else {
msg.channel.createMessage(uri);
}
});
};
it('convert a svg with an image', function (done) {
this.timeout(5000);
var imageUrl = 'https://zh.wikipedia.org/static/images/project-logos/zhwiki-hans.png';
Image64.encode(imageUrl, {}, function (err, base64) {
var svgString = util.format('<svg height="258" width="540" version="1.1" xmlns="http://www.w3.org/2000/svg"><image href="%s" y="0" x="0" height="258" width="540"></image></svg>', 'data:image/png;base64,' + base64.toString('base64'));
svg2img(svgString, function(error, data) {
expect(error).not.to.be.ok();
expect(Buffer.isBuffer(data)).to.be.ok();
expect(data.length).to.be.above(0);
done();
});
});
});