Advertisement
ASKARM

captcha 2/2

Jun 3rd, 2020
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Jimp = require('jimp');
  2.  
  3. module.exports = async function createCaptcha() {
  4.     const captcha = Math.random().toString(36).slice(2, 8);
  5.     const image = new Jimp(175, 50, 'white');
  6.     const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
  7.     const w = image.bitmap.width;
  8.     const h = image.bitmap.height;
  9.     const textWidth = Jimp.measureText(font, captcha);
  10.     const textHeight = Jimp.measureTextHeight(font, captcha);
  11.     image.print(font, (w/2 - textWidth/2), (h/2 - textHeight/2), captcha);
  12.     image.fisheye({"r": 1.5});
  13.     let ImageBuffer;
  14.     image.getBuffer("image/png", function (Err, Buf) {
  15.       ImageBuffer = Buf;
  16.     });
  17.     return {
  18.       "text": captcha,
  19.       "image": ImageBuffer
  20.     };
  21. }
  22. Fichier séparé du fichier captcha 1/2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement