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

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.

  • 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 – Ankit Shah Oct 21 '16 at 8:07
  • @AnkitShah updated my answer. – Khoa TruongDinh Oct 21 '16 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? – Ankit Shah Nov 1 '16 at 7:55
  • @AnkitShah you should read here: magento.stackexchange.com/questions/136156/… – Khoa TruongDinh Nov 1 '16 at 8:16
  • @AnkitShah why you need to override the Zend library? – Khoa TruongDinh Nov 1 '16 at 8:29
0

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

magento2/vendor/magento/zendframework1/library/Zend/Captcha/Image.php
  • Yes you are right @Nikunj. But how to orverride this file? – Ankit Shah Nov 1 '16 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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