Skip to content

Instantly share code, notes, and snippets.

@MilesCranmer
Created December 18, 2022 21:36
Show Gist options
  • Save MilesCranmer/c5c7bbbdc61fa59b984bf22a8aaa7c89 to your computer and use it in GitHub Desktop.
Save MilesCranmer/c5c7bbbdc61fa59b984bf22a8aaa7c89 to your computer and use it in GitHub Desktop.
Generate captcha text to hide text from bots
<?php
require_once 'vendor/autoload.php';
use Gregwar\Captcha\CaptchaBuilder;
// Create a captcha with the text "MilesCranmer@mastodon.social"
$builder = new CaptchaBuilder('MilesCranmer@mastodon.social');
$builder->setMaxBehindLines(10);
$builder->setMaxFrontLines(10);
// Change the "font" to wherever your desired font file is
$builder->build($width=2000, $height=800, $font='/Users/mcranmer/Library/Fonts/Roboto-Regular.ttf');
$builder->save('out.jpg', $quality=100);
@MilesCranmer
Copy link
Author

In case it's still legible to OCR, you can increase the number of lines by changing the 10s. You can also change the font.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment