captcha-canvas
    Preparing search index...

    Class CaptchaGenerator

    Captcha generator class.

    Index

    Constructors

    • Initatiates the creation of captcha image generation.

      Parameters

      • Optionaloptions: { height: number; width: number } = ...

        Options for constructor.

        • height: number

          Height of captcha image.

        • width: number

          Width of captcha image.

      Returns CaptchaGenerator

      const captcha = new CaptchaGenerator({height: 200, width: 600});
      

      2.0.0

    Accessors

    Methods

    • Method which returns image buffer

      Returns Promise<Buffer>

      const { CaptchaGenerator } = require("captcha-canvas");
      const fs = require("fs")
      const captcha = new CaptchaGenerator();
      const buffer = await captcha.generate() //generate image

      fs.writeFileSync("image.png", buffer)

      2.0.0

    • Non asynchronous method to generate captcha image.

      Note: It do not use setBackground method value for background image. If you want to set background and also use generateSync method then use background option in genrateSync method.

      Parameters

      • Optionaloption: { background?: Image } = {}

        Options to add extra values

        • Optionalbackground?: Image

          Add background image.

      Returns Buffer

      const { CaptchaGenerator, resolveImage } = require("captcha-canvas");
      const fs = require("fs");
      const img = await resolveImage("./path/to/file");

      const captcha = new CaptchaGenerator()
      .generateSync({background: img});

      fs.writeFileSync("image.png", captcha);

      2.2.0

    • Set background for captcha image.

      Parameters

      • image: string | Buffer

        Buffer/url/path of image.

      Returns CaptchaGenerator

      const { CaptchaGenerator } = require("captcha-canvas");
      const fs = require("fs")
      const captcha = new CaptchaGenerator();
      captcha.setBackground("./path/toFile");
      const buffer = await captcha.generate() //generate image

      fs.writeFileSync("image.png", buffer)

      2.0.0

    • set dimension for your captcha image

      Parameters

      • height: number

        Height of captcha image.

      • width: number

        Width of captcha image.

      Returns CaptchaGenerator

      const { CaptchaGenerator } = require("captcha-canvas");
      const fs = require("fs")
      const captcha = new CaptchaGenerator();
      captcha.setDimension(200, 600);
      const buffer = await captcha.generate() //generate image

      fs.writeFileSync("image.png", buffer)

      2.0.0

    • Change trace creation options.

      Parameters

      Returns CaptchaGenerator

      const { CaptchaGenerator } = require("captcha-canvas");
      const fs = require("fs")
      const captcha = new CaptchaGenerator();
      const option = {size: 5, color: "deeppink"}
      captcha.setTrace(option)
      const buffer = await captcha.generate() //generate image

      fs.writeFileSync("image.png", buffer)

      2.0.0