Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Jimp = require('jimp');
- module.exports = async function createCaptcha() {
- const captcha = Math.random().toString(36).slice(2, 8);
- const image = new Jimp(175, 50, 'white');
- const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
- const w = image.bitmap.width;
- const h = image.bitmap.height;
- const textWidth = Jimp.measureText(font, captcha);
- const textHeight = Jimp.measureTextHeight(font, captcha);
- image.print(font, (w/2 - textWidth/2), (h/2 - textHeight/2), captcha);
- image.fisheye({"r": 1.5});
- let ImageBuffer;
- image.getBuffer("image/png", function (Err, Buf) {
- ImageBuffer = Buf;
- });
- return {
- "text": captcha,
- "image": ImageBuffer
- };
- }
- Fichier séparé du fichier captcha 1/2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement