4

In Mangeto 2 We have default Captcha, which is not easily readable.

So how to change/customize Font Name it's Color & Background

enter image description here

enter image description here

3 Answers 3

4

Color & Background

Magento builds its Model Captcha which extends from Zend_Captcha_Image class. So, in your case, we should override Magento\Captcha\Model\DefaultModel class.

<preference for="Magento\Captcha\Model\DefaultModel"
            type="Vendor\Module\Model\DefaultModel"/>

We need to override _generateImage method.

protected function _generateImage($id, $word)
{
      ......
      $w     = $this->getWidth();
      $h     = $this->getHeight();
      $fsize = $this->getFontSize();
      ......
}

We can remove the generation noise:

enter image description here

Custom Font

Add new font to the default config:

app/code/Company/Module/etc/config.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <captcha translate="label">
            <fonts>
                <arial>
                    <label>Arial</label>
                    <path>CustomFont/Arial.ttf</path>
                </arial>
            </fonts>
        </captcha>
    </default>
</config>

Add our custom font: lib/internal/CustomFont/Arial.ttf

enter image description here

Take a look: vendor/magento/module-captcha/Helper/Data.php::getFonts() to see more details.

14
  • Hi @Khoa. Thanks for answer. Appreciated. Can you please give frontend captcha screenshot as well? How it looks like & how can change/set different background with Font match color
    – Jackson
    Commented Oct 21, 2016 at 8:07
  • @AnkitShah updated my answer. Commented Oct 21, 2016 at 8:19
  • Hi @Khoa File is here vendor\magento\zendframework1\library\Zend\Captcha\Image.php How to Orverwrite this file? I already removed noise from here. Where to put in app\code?
    – Jackson
    Commented Nov 1, 2016 at 7:55
  • @AnkitShah you should read here: magento.stackexchange.com/questions/136156/… Commented Nov 1, 2016 at 8:16
  • @AnkitShah why you need to override the Zend library? Commented Nov 1, 2016 at 8:29
0

For Captcha customise I think you need change in this file :

magento2/vendor/magento/zendframework1/library/Zend/Captcha/Image.php
1
  • Yes you are right @Nikunj. But how to orverride this file?
    – Jackson
    Commented Nov 1, 2016 at 8:02
0

in Magento ver. 2.4.4 just edit : /vendor/magento/module-captcha/Model/DefaultModel.php

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.