Download the PHP package visavi/captcha without Composer

On this page you can find all versions of the php package visavi/captcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package captcha

Captcha

Latest Stable Version Total Downloads Latest Unstable Version License

Animated GIF captcha for PHP. The phrase is never shown at once: a narrow window slides over the text, so a human reads it frame by frame while a single frame gives a bot almost nothing.

Installation

Requires PHP 8.0+ and ext-gd compiled with FreeType support.

Usage

Serve the captcha as an image:

Or embed it straight into the page, no separate request and no headers needed:

Then check the answer, and drop the phrase so it cannot be replayed:

Configuration

Every setter is optional and returns $this, so calls can be chained:

Method Default Description
setWidth(int $width) 150 Image width, px
setHeight(int $height) 40 Image height, px
setTextColor(int $r, int $g, int $b) random dark Text color
setBackgroundColor(int $r, int $g, int $b) random light Background color
setFont(string $path) random bundled font Path to a TTF font
setWindowWidth(int $width) 75 Width of the sliding window, px
setPixelPerFrame(int $pixel) 15 Window shift per frame, px — smaller is smoother and heavier
setDelayBetweenFrames(int $delay) 20 Delay between frames, in hundredths of a second

Reading the result:

Method Description
getPhrase() The phrase the user is expected to type
render() Binary GIF contents
inline() Base64 data: URI, ready for <img src>
getFrames() Raw frames, if you want to encode them yourself

Colors and inversion are random unless set explicitly, so the same settings still give a different looking image every time.

Both colors and the phrase are left untouched when you set them yourself; everything else — font, inversion, and the exact window width — is decided per image.

How the window works

setWindowWidth() is an upper bound, not an exact value. Before rendering, the window is shrunk until no frame can show the whole phrase: narrow fonts, short phrases and wide windows are all handled, and the guarantee holds for every frame, including the ones where the window wraps around the edge of the image.

The number of frames is width / pixelPerFrame, evened out so the last frame lands back on the first — the animation loops without a visible jump. So a 150 px image with the default 15 px step is 10 frames.

Examples

Same size and settings, different bundled fonts:

Different window width and speed — 40 px window at 4 px/frame, 75 at 10, 120 at 25:

Mini, 100×30 with a 4 character phrase:

Phrases

PhraseBuilder generates the phrase with random_int(). The default charset skips characters that are easy to misread — i, l, o, 0, 1:

A custom charset is split by code points, so multibyte phrases work — provided the font has the glyphs. Of the bundled fonts only fonts/5.ttf covers Cyrillic; for anything else pass your own font via setFont().

License

The class is open-sourced software licensed under the MIT license


All versions of captcha with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.0
ext-gd Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package visavi/captcha contains the following files

Loading the files please wait ...