{"id":13405135,"url":"https://github.com/Gregwar/Captcha","last_synced_at":"2025-03-14T09:32:23.583Z","repository":{"id":6112033,"uuid":"7339809","full_name":"Gregwar/Captcha","owner":"Gregwar","description":"PHP Captcha library","archived":false,"fork":false,"pushed_at":"2024-05-14T15:58:26.000Z","size":658,"stargazers_count":1714,"open_issues_count":48,"forks_count":288,"subscribers_count":62,"default_branch":"master","last_synced_at":"2024-10-15T04:41:12.883Z","etag":null,"topics":["anti-bot","anti-spam","bots","captcha","php","security"],"latest_commit_sha":null,"homepage":"","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/Gregwar.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-12-27T12:01:19.000Z","updated_at":"2024-10-14T07:54:50.000Z","dependencies_parsed_at":"2023-01-13T13:50:32.106Z","dependency_job_id":"79928fe8-b77c-4867-9d1d-8768b96e3b78","html_url":"https://github.com/Gregwar/Captcha","commit_stats":{"total_commits":91,"total_committers":28,"mean_commits":3.25,"dds":0.4505494505494505,"last_synced_commit":"6e5b61b66ac89885b505153f4ef9a74ffa5b3074"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gregwar%2FCaptcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gregwar%2FCaptcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gregwar%2FCaptcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gregwar%2FCaptcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gregwar","download_url":"https://codeload.github.com/Gregwar/Captcha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221454074,"owners_count":16824598,"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","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":["anti-bot","anti-spam","bots","captcha","php","security"],"created_at":"2024-07-30T19:01:56.268Z","updated_at":"2024-10-25T19:31:42.726Z","avatar_url":"https://github.com/Gregwar.png","language":"PHP","readme":"Captcha\n=======\n\n![Captchas examples](http://gregwar.com/captchas.png)\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=YUXRLWHQSWS6L)\n\nInstallation\n============\n\nWith composer :\n\n``` json\n{\n    ...\n    \"require\": {\n        \"gregwar/captcha\": \"1.*\"\n    }\n}\n```\n\nUsage\n=====\n\nYou can create a captcha with the `CaptchaBuilder` :\n\n```php\n\u003c?php\n\nuse Gregwar\\Captcha\\CaptchaBuilder;\n\n$builder = new CaptchaBuilder;\n$builder-\u003ebuild();\n```\n\nYou can then save it to a file :\n\n```php\n\u003c?php\n\n$builder-\u003esave('out.jpg');\n```\n\nOr output it directly :\n\n```php\n\u003c?php\n\nheader('Content-type: image/jpeg');\n$builder-\u003eoutput();\n```\n\nOr inline it directly in the HTML page:\n\n```php\n\u003cimg src=\"\u003c?php echo $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\u003c?php\n\n// Example: storing the phrase in the session to test for the user \n// input later\n$_SESSION['phrase'] = $builder-\u003egetPhrase();\n```\n\nYou can compare the phrase with user input:\n```php\nif($builder-\u003etestPhrase($userInput)) {\n    // instructions if user phrase is good\n}\nelse {\n    // user phrase is wrong\n}\n```\n\nAPI\n===\n\nYou can use theses functions :\n\n* **__construct($phrase = null)**, constructs the builder with the given phrase, if the phrase is null, a random one will be generated\n* **getPhrase()**, allow you to get the phrase contents\n* **setDistortion($distortion)**, enable or disable the distortion, call it before `build()`\n* **isOCRReadable()**, returns `true` if the OCR can be read using the `ocrad` software, you'll need to have shell_exec enabled, imagemagick and ocrad installed\n* **buildAgainstOCR($width = 150, $height = 40, $font = null)**, builds a code until it is not readable by `ocrad`\n* **build($width = 150, $height = 40, $font = null)**, builds a code with the given $width, $height and $font. By default, a random font will be used from the library\n* **save($filename, $quality = 80)**, saves the captcha into a jpeg in the $filename, with the given quality\n* **get($quality = 80)**, returns the jpeg data\n* **output($quality = 80)**, directly outputs the jpeg code to a browser\n* **setBackgroundColor($r, $g, $b)**, sets the background color to force it (this will disable many effects and is not recommended)\n* **setBackgroundImages(array($imagepath1, $imagePath2))**, Sets custom background images to be used as captcha background. It is recommended to disable image effects when passing custom images for background (ignore_all_effects). A random image is selected from the list passed, the full paths to the image files must be passed.\n* **setInterpolation($interpolate)**, enable or disable the interpolation (enabled by default), disabling it will be quicker but the images will look uglier\n* **setIgnoreAllEffects($ignoreAllEffects)**, disable all effects on the captcha image. Recommended to use when passing custom background images for the captcha.\n* **testPhrase($phrase)**, returns true if the given phrase is good\n* **setMaxBehindLines($lines)**, sets the maximum number of lines behind the code\n* **setMaxFrontLines($lines)**, sets the maximum number of lines on the front of the code\n\nIf you want to change the number of character, you can call the phrase builder directly using\nextra parameters:\n\n```php\nuse Gregwar\\Captcha\\CaptchaBuilder;\nuse Gregwar\\Captcha\\PhraseBuilder;\n\n// Will build phrases of 3 characters\n$phraseBuilder = new PhraseBuilder(4);\n\n// Will build phrases of 5 characters, only digits\n$phraseBuilder = new PhraseBuilder(5, '0123456789');\n\n// Pass it as first argument of CaptchaBuilder, passing it the phrase\n// builder\n$captcha = new CaptchaBuilder(null, $phraseBuilder);\n```\n\nYou can also pass directly the wanted phrase to the builder:\n\n```php\n// Building a Captcha with the \"hello\" phrase\n$captcha = new CaptchaBuilder('hello');\n```\n\nComplete example\n================\n\nIf you want to see an example you can have a look at the ``demo/form.php``, which uses ``demo/session.php`` to\nrender a captcha and check it after the submission\n\nSymfony Bundle\n================\n\nYou can have a look at the following repository to enjoy the Symfony 2 bundle packaging this captcha generator :\nhttps://github.com/Gregwar/CaptchaBundle\n\nYii2 Extension\n===============\n\nYou can use the following extension for integrating with Yii2 Framework :\nhttps://github.com/juliardi/yii2-captcha\n\nLicense\n=======\n\nThis library is under MIT license, have a look to the `LICENSE` file\n","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=YUXRLWHQSWS6L"],"categories":["PHP","Biblioteki","目录","类库","常用验证码库","图像( Imagery )"],"sub_categories":["图像 Imagery","图像处理"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGregwar%2FCaptcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGregwar%2FCaptcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGregwar%2FCaptcha/lists"}