{"id":18499750,"url":"https://github.com/s1syphos/php-simple-captcha","last_synced_at":"2025-08-02T15:34:13.339Z","repository":{"id":53771670,"uuid":"502136963","full_name":"S1SYPHOS/php-simple-captcha","owner":"S1SYPHOS","description":"Simple captcha generator","archived":false,"fork":false,"pushed_at":"2023-02-06T10:55:23.000Z","size":1983,"stargazers_count":24,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-17T03:08:22.330Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://codeberg.org/S1SYPHOS/php-simple-captcha","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/S1SYPHOS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-10T18:04:08.000Z","updated_at":"2024-11-19T02:09:01.000Z","dependencies_parsed_at":"2023-02-19T06:45:54.753Z","dependency_job_id":null,"html_url":"https://github.com/S1SYPHOS/php-simple-captcha","commit_stats":null,"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"purl":"pkg:github/S1SYPHOS/php-simple-captcha","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1SYPHOS%2Fphp-simple-captcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1SYPHOS%2Fphp-simple-captcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1SYPHOS%2Fphp-simple-captcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1SYPHOS%2Fphp-simple-captcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/S1SYPHOS","download_url":"https://codeload.github.com/S1SYPHOS/php-simple-captcha/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1SYPHOS%2Fphp-simple-captcha/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268411309,"owners_count":24246229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T13:47:08.983Z","updated_at":"2025-08-02T15:34:13.278Z","avatar_url":"https://github.com/S1SYPHOS.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-simple-captcha\n[![Build](https://ci.codeberg.org/api/badges/S1SYPHOS/php-simple-captcha/status.svg)](https://codeberg.org/S1SYPHOS/php-simple-captcha/issues)\n\n![Example captcha images](examples.png)\n\n`php-simple-captcha` creates \u0026 verifies captcha images, dependency-free \u0026 respecting your user's privacy. It's a fork of [`Gregwar/Captcha`](https://github.com/Gregwar/Captcha), but supports modern PHP versions and comes with several new features \u0026 bug fixes.\n\n\n## Installation\n\nIt's available for [Composer](https://getcomposer.org):\n\n```text\ncomposer require s1syphos/php-simple-captcha\n```\n\n\n## Getting started\n\nUpon invoking the main class, you may specify a phrase (the string hidden in the captcha image), otherwise one will be created randomly:\n\n```php\n\u003c?php\n\nrequire_once('vendor/autoload.php');\n\nuse SimpleCaptcha\\Builder;\n\n# First, you have to instantiate it ..\n# (1) .. either this way ..\n$builder = new Builder;\n\n# (2) .. or this way\n$builder = Builder::create();\n\n# Now, building a captcha is easy\n$builder-\u003ebuild();\n```\n\nIf you want the generated phrase to be *even more random*, `buildPhrase()` has your back:\n\n```php\n# Create random phrase ..\n# (1) .. consisting of 32 characters\n# (2) .. being randomly chosen from 'abc@123'\n$phrase = Builder::buildPhrase(32, 'abc@123');\n\n# Now proceed like above ..\n# (1) .. either this way ..\n$builder = new Builder($phrase);\n\n# (2) .. or this way\n$builder = Builder::create($phrase);\n```\n\nFrom here, you can ..\n\n**(1)** .. save the captcha to a file:\n\n```php\n$builder-\u003esave('out.jpg');\n\n# GIF \u0026 PNG are also supported, so this works too:\n$builder-\u003esave('out.png');\n$builder-\u003esave('out.gif');\n\n# Optionally, quality may be specified:\n# - JPG: 0-100\n# - PNG: 0-9\n$builder-\u003esave('low-quality.jpg', 40);\n```\n\n**(2)** .. output it directly in the browser:\n\n```php\n# Default: JPG \u0026 90\n$builder-\u003eoutput();\n\n# .. but how about ..\n$builder-\u003eoutput(6, 'png');\n```\n\n**(3)** .. inline its data URI in your HTML:\n\n```php\n\u003cimg src=\"\u003c?= $builder-\u003einline() ?\u003e\" /\u003e\n```\n\nYou'll be able to get the code and compare it with a user input:\n\n```php\n# Example: storing the phrase in the session to test for the user input later\n$_SESSION['phrase'] = $builder-\u003ephrase;\n```\n\n**Note:** Since one of the randomly selected fonts may contain letters looking very similar, you should validate user input using `compare()`, otherwise you might end up with unsolvable captchas:\n\n```php\nif ($builder-\u003ecompare($input)) {\n    # Valid phrase\n} else {\n    # Invalid phrase\n}\n```\n\n\n## Usage\n\nFrom there, the following functions are available:\n\n\n### `randomCharacter(string $charset = null): string`\n\nPicks random character (using given charset)\n\n\n### `buildPhrase(int $length = 5, string $charset = null): string`\n\nBuilds random phrase (of given length using given charset)\n\n\n### `build(int $width = 150, int $height = 40): self`\n\nBuilds captcha image\n\n\n### `buildAgainstOCR(int $width = 150, int $height = 40): self`\n\nBuilds captcha image until it is (supposedly) unreadable by OCR software\n\n\n### `save(string $filename, int $quality = 90): void`\n\nSaves captcha image to file\n\n\n### `output(int $quality = 90, string $type = 'jpg'): void`\n\nOutputs captcha image directly\n\n\n### `fetch(int $quality = 90, string $type = 'jpg'): string`\n\nFetches captcha image contents\n\n\n### `inline(int $quality = 90, string $type = 'jpg'): string`\n\nFetches captcha image as data URI\n\n\n### `compare(string $phrase, string $string = null): bool`\n\nChecks whether captcha was solved correctly. Upon passing another string, both strings are compared (instead of first string \u0026 current phrase).\n\n\n## Configuration\n\nThere are several settings you may use in order to change the behavior of the library:\n\n\n### `$builder-\u003ephrase (string)`\n\nCaptcha phrase. Default: random, see `buildPhrase()`\n\n\n### `$builder-\u003efonts (array)`\n\nPaths to captcha fonts. Default: Font files inside `fonts`\n\n\n### `$builder-\u003edistort (bool)`\n\nWhether to distort the image. Default: `true`\n\n\n### `$builder-\u003einterpolate (bool)`\n\nWhether to interpolate the image. Default: `true`\n\n\n### `$builder-\u003emaxLinesBehind (int)`\n\nMaximum number of lines behind the captcha phrase. Default: random\n\n\n### `$builder-\u003emaxLinesFront (int)`\n\nMaximum number of lines in front of the captcha phrase. Default: random\n\n\n### `$builder-\u003emaxAngle (int)`\n\nMaximum character angle. Default: `8`\n\n\n### `$builder-\u003emaxOffset (int)`\n\nMaximum character offset. Default: `5`\n\n\n### `$builder-\u003ebgColor (array|string)`\n\nBackground color, either RGB values (array), HEX value or `'transparent'` (string). Default: random\n\n\n### `$builder-\u003elineColor (array|string)`\n\nLine color RGB values (array) or HEX value (string)\n\n\n### `$builder-\u003etextColor (array|string)`\n\nText color RGB values (array) or HEX value (string)\n\n\n### `$builder-\u003ebgImage (string)`\n\nPath to background image. Default: background fill, see `bgColor`\n\n\n### `$builder-\u003eapplyEffects (bool)`\n\nWhether to apply any effects. Default: `true`\n\n\n### `$builder-\u003eapplyNoise (bool)`\n\nWhether to apply background noise (using random letters). Default: `true`\n\n\n### `$builder-\u003enoiseFactor (int)`\n\nMultiples of phrase length to be used for noise generation. Default: `2`\n\n\n### `$builder-\u003eapplyPostEffects (bool)`\n\nWhether to apply post effects. Default: `true`\n\n\n### `$builder-\u003eapplyScatterEffect (bool)`\n\nWhether to enable scatter effect. Default: `true`\n\n\n### `$builder-\u003erandomizeFonts (bool)`\n\nWhether to use random font for each symbol. Default: `true`\n\n\n## Examples\n\nHave a look at the examples inside the `demo` folder, which should give you an impression of what's possible - or simply whip up a PHP development server:\n\n```bash\n# Change directory\ncd demo\n\n# Launch server\nphp -S localhost:3000\n\n# All examples are now available in your browser, eg 'http://localhost:3000/ocr.php'\n```\n\n\n## Fonts\n\nThe `fonts` directory includes:\n\n- [Bitter](https://www.solmatas.com/bitter) (licensed under [OFL](https://scripts.sil.org/OFL))\n- [Gidole](https://gidole.github.io) (licensed under [MIT](https://github.com/larsenwork/Gidole/blob/master/Resources/GidoleFont/License.txt))\n- [Hack](https://sourcefoundry.org/hack) (licensed under [MIT](https://github.com/source-foundry/Hack/blob/master/LICENSE.md))\n- [Linux Libertine](https://libertine-fonts.org) (licensed under [OFL](https://scripts.sil.org/OFL))\n- [TGL 0-17](http://www.peter-wiegel.de/TGL_0-16.html) (licensed under [OFL](https://scripts.sil.org/OFL))\n- [Vollkorn](http://vollkorn-typeface.com) (licensed under [OFL](https://scripts.sil.org/OFL))\n\n\n## Credits\n\nThis library is based on [`Gregwar/Captcha`](https://github.com/Gregwar/Captcha), introducing several new features \u0026 bug fixes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs1syphos%2Fphp-simple-captcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs1syphos%2Fphp-simple-captcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs1syphos%2Fphp-simple-captcha/lists"}