Font Preview and Image captcha is not displaying.

Created on 13 July 2023, over 1 year ago
Updated 4 December 2023, about 1 year ago

Problem/Motivation

I have Drupal 9.4.8 project running with PHP 8.1.13. There is a requirement to set Image captcha for a form. I have configured Image captcha for the form and thought the image captcha would render for the anonymous user but the Font preview is not rendering for Admin user and also the Image captcha is not rendering for the Anonymous User as well. I have tried installing a fresh Drupal 9.4.8 and Captcha 8.x-1.10 in my local and found the captcha is working perfect! There is something wrong with my other Drupal project. I am totally clueless. Will be grateful if anyone comes forward to help.

Steps to reproduce

NA

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: works as designed

Version

1.13

Component

Image Captcha (image_captcha)

Created by

🇮🇳India saranyamariappan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @saranyamariappan
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @saranyamariappan, might this be the same as 🐛 Error 500 in image_captcha image Closed: cannot reproduce

    Please help us find out the reasons, and thanks for testing. Are there any differences? If it's the same issue, please close this as duplicate.

  • I am also having this issue on my end.

    Attached the screenshot how it looks in the form.

  • Status changed to Closed: duplicate over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica
  • Assigned to saranyamariappan
  • Status changed to Active over 1 year ago
  • 🇮🇳India saranyamariappan

    The issue that I'm facing is a different one and I would like to reopen the issue.

  • 🇩🇪Germany Anybody Porta Westfalica

    You're welcome @saranyamariappan - could you provide further details, like the error message from the logs for example or the error that appears, if you try to open the broken image URL?

  • 🇮🇳India pankaj.g

    Hi @Saranyamariappan and @Anybody.

    I have tested the attached patch and it is working fine without any other issues. I need your confirmation too on this. Thanks.

  • Issue was unassigned.
  • Status changed to Needs work over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    #7 must be wrong, I think. Can you please explain the change?
    I'd understand ob_flush() somewhere, but discaring the content doesn't make any sense to me.

  • 🇧🇪Belgium ericvl

    In your problem description, you stated that the version 1.10 is working perfectly.
    Why do you assign the version 1.10 then to this issue? Should it rather not be 1.13?
    Just a question.

  • 🇩🇪Germany Anybody Porta Westfalica

    Indeed!

  • 🇮🇳India saranyamariappan

    Hi @ anybody ,

    The Image captcha is not rendering on any of the form that I configure it, on my project. Please find the screenshots of the Image Response URL where you could see only the broken image. This is happening for Font Preview as well. Adding ob_clean() at public function image() {} and public function getFont($token) {} is fixing the issue on my local. Please share your thoughts on this, also let me know if you need any.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @saranyamariappan - what's the error message logged in PHP log or Drupal log, when accessing the broken image URL?
    We have to find the root cause. ob_flush() won't solve the root cause, I'm quite sure. It's just a hack.

  • Status changed to Closed: works as designed over 1 year ago
  • 🇩🇪Germany Grevil

    Please run drush updb after updating. This will fix the problem.

    The issue was originally caused by Difficult migration from Drupal 9 to 10 Fixed where all newer releases of 8.x-1.x were synchronized with 2.x INCLUDING moving image_captcha in the correct "modules" directory, which broke the image path.
    This was already mentioned by @Anybody in 🐛 Error 500 in image_captcha image Closed: cannot reproduce .

  • 🇮🇳India saranyamariappan

    @Anybody , @Grevil

    I have updated the captcha module to 2.0.4, My local PHP version (likely WAMP64) is PHP 8.1.13, my composer.json previously had PHP:7.4 and this time I have updated it to PHP 8.1. I did drush updb followed by drush cr as well.

    I had PHP error.log

    TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php on line 256 #0 C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php(256): preg_match('/^([\\w\\-]+):\\/\\...', Array, NULL)
    #1 C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php(103): Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme(Array)
    #2 C:\wamp64\www\\docroot\core\lib\Drupal\Core\File\FileSystem.php(135): Drupal\Core\StreamWrapper\StreamWrapperManager->getViaUri(Array)

    I have applied the Patch mentioned on https://www.drupal.org/project/captcha/issues/3368540 🐛 Error 500 in image_captcha image Closed: cannot reproduce

    and now the PHP error.log has no errors reported. But still the Image Captcha and Font Preview is not working. When I inspected the /image-captcha-generate/80/1691138045 no watchdog error and PHP error.log.

    Please let me know how to proceed from here.

    In Addition, I would like to highlight here that,
    My Drupal version is 9.4.8 and I ran composer require 'drupal/captcha:^2.0' copied from the Captcha module page. I totally believed that this composer require would work on my local without any error as it was mentioned

    Works with Drupal: >=9.4 <11

    but I got the error attached. Please make note of it. If it is mentioned >=9.4, then it should work with 9.4.8 but it is requiring 10, Please clarify this as well.

  • Status changed to Active over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    @saranyamariappan please try composer update -W, while I don't think it will fix the issue I don't really understand why composer says that captcha requires Drupal 10?!

    TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php on line 256 #0 C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php(256): preg_match('/^([\\w\\-]+):\\/\\...', Array, NULL)
    #1 C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php(103): Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme(Array)
    #2 C:\wamp64\www\\docroot\core\lib\Drupal\Core\File\FileSystem.php(135): Drupal\Core\StreamWrapper\StreamWrapperManager->getViaUri(Array) 

    Is this the full backtrace? Looks like the important parts (#3 ...) are missing?

    Which HTML Statuscode does /image-captcha-generate/80/1691138045 (you'll need to use a fresh URL) return?

    I still think this is a duplicate of one of the existing issues, but let's see...

  • 🇩🇪Germany Anybody Porta Westfalica

    Seems to be very specific to your installation.

  • 🇮🇳India saranyamariappan

    Please find below the details you are requesting,

    TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php on line 287 #0 C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php(287): preg_match('/^([\\w\\-]+):\\/\\...', Array, NULL)
    #1 C:\wamp64\www\\docroot\core\lib\Drupal\Core\StreamWrapper\StreamWrapperManager.php(104): Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme(Array)
    #2 C:\wamp64\www\\docroot\core\lib\Drupal\Core\File\FileSystem.php(135): Drupal\Core\StreamWrapper\StreamWrapperManager->getViaUri(Array)
    #3 C:\wamp64\www\\docroot\modules\contrib\s3fs\src\S3fsFileService.php(152): Drupal\Core\File\FileSystem->realpath(Array)
    #4 C:\wamp64\www\\docroot\modules\contrib\captcha\modules\image_captcha\src\Service\ImageCaptchaRenderService.php(335): Drupal\s3fs\S3fsFileService->realpath(Array)
    #5 C:\wamp64\www\\docroot\modules\contrib\captcha\modules\image_captcha\src\Service\ImageCaptchaRenderService.php(118): Drupal\image_captcha\Service\ImageCaptchaRenderService->printString(Object(GdImage), 180, 60, Array, 30, '5hEQE')
    #6 C:\wamp64\www\\docroot\modules\contrib\captcha\modules\image_captcha\src\Controller\CaptchaImageGeneratorController.php(123): Drupal\image_captcha\Service\ImageCaptchaRenderService->generateImage('5hEQE')
    #7 [internal function]: Drupal\image_captcha\Controller\CaptchaImageGeneratorController->image(Object(Symfony\Component\HttpFoundation\Request))
    #8 C:\wamp64\www\\docroot\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)

    /image-captcha-generate/80/1691138045 - StatusCode is 200

  • 🇧🇪Belgium ericvl

    @saranyamariappan
    May be you did a "composer require drupal/captcha:2.0" and forgot the "^" before the version spec.
    Indeed version 2.0.0 only works with Drupal 10 and higher.
    If you did rather a "composer require drupal/captcha:^2.0" then composer should select a later version than 2.0.0 (.1, .2, .3 or .4) and these versions are Drupal >=9.4 <11 compatible.

  • 🇩🇪Germany Anybody Porta Westfalica

    @EricVL GOOD POINT!! I think that's it! Great :)

  • 🇮🇳India saranyamariappan

    We have our Composer running with PHP 7.4 and Drupal 9.4.8, using "drupal/captcha": "^1.2" [copied from my composer.json], I have fixed it with ob_clean() for timebeing. We are in process of upgrading to PHP 8.1 in another couple of weeks and I will check the same issue with Captcha 2.x and confirm if the issue still persists. As of now, we can close the ticket(as it is edge case for specific project).

    Thanks for all who has spent their time on this issue queue.

  • Status changed to Closed: works as designed over 1 year ago
  • 🇩🇪Germany Grevil

    Alright.

  • 🇨🇦Canada sdsheridan Toronto

    I'm running into the same issue, and the ob_clean() call of #7 above at least now generated the captcha image, although the fonts are still not previewing properly.

    • Drupal 10.1.6
    • PHP 8.1.13 and 8.1.26
    • GD 2.1.0 and 2.3.3
    • Captcha 2.0.5
Production build 0.71.5 2024