/vendor/gregwar/captcha/demo/ocr.php

https://bitbucket.org/JakeZerafa/thechangeinitiative-website · PHP · 42 lines · 27 code · 11 blank · 4 comment · 3 complexity · acdb0f1e294c85604eca4c10e0b9355d MD5 · raw file

  1. <?php
  2. include(__DIR__.'/../CaptchaBuilderInterface.php');
  3. include(__DIR__.'/../PhraseBuilderInterface.php');
  4. include(__DIR__.'/../CaptchaBuilder.php');
  5. include(__DIR__.'/../PhraseBuilder.php');
  6. use Gregwar\Captcha\CaptchaBuilder;
  7. /**
  8. * Generates 1000 captchas and try to read their code with the
  9. * ocrad OCR
  10. */
  11. $tests = 10000;
  12. $passed = 0;
  13. shell_exec('rm passed*.jpg');
  14. for ($i=0; $i<$tests; $i++) {
  15. echo "Captcha $i/$tests... ";
  16. $captcha = new CaptchaBuilder;
  17. $captcha
  18. ->setDistortion(false)
  19. ->build()
  20. ;
  21. if ($captcha->isOCRReadable()) {
  22. $passed++;
  23. $captcha->save("passed$passed.jpg");
  24. echo "passed at ocr... ";
  25. } else {
  26. echo "failed... ";
  27. }
  28. echo "pass rate: ".round(100*$passed/($i+1),2)."%\n";
  29. }
  30. echo "\n";
  31. echo "Over, $passed/$tests readed with OCR\n";