8

Hello All
I want to change the layout of my captcha on contact form. I need to decrease the amount of lines and dots it contains so, a user can see the text more clearly.
Does anyone have any idea how to do it?
Thanks in advance.

11

The way you did answer above is not a good approach.

The class Zend_Captcha_Image has provided functions to change the variables. You can find the functions in the same class which will be something like this:

public function setDotNoiseLevel ($dotNoiseLevel)
{
    $this->_dotNoiseLevel = $dotNoiseLevel;
    return $this;
}
/**
 * @param int $lineNoiseLevel
 */
public function setLineNoiseLevel ($lineNoiseLevel)
{
    $this->_lineNoiseLevel = $lineNoiseLevel;
    return $this;
}

And also Zend_Captcha_Image is extended to a Mage model class i.e Mage_Captcha_Model_Zend. So, you can easily override this Mage model class to set those variables.

In Mage_Captcha_Model_Zend:

public function __construct($params)
{
    if (!isset($params['formId'])) {
        throw new Exception('formId is mandatory');
    }
    $this->_formId = $params['formId'];
    $this->setExpiration($this->getTimeout());

    $this->setDotNoiseLevel(10);     // Added code
    $this->setLineNoiseLevel(0);     // Added code
}

I am setting those variables in constructor so that the changes will work even for page load and also for captcha refresh.

It will be better if you override the above function instead of modifying mage core files.

8

You can change the captcha noise using below code.

Go to : lib/Zend/Captcha/Image.php

Change below variable values as per your requirements

protected $_dotNoiseLevel = 10; // Increase the value if you want to increase amount of dots
protected $_lineNoiseLevel = 0; // Increase the value if you want to increase amount of lines

Reference : http://magentoforall.blogspot.com.au/2012/11/magento-change-captcha-background-lines.html

3

For Magento 2 : Go to vendor\magento\zendframework1\library\Zend\Captcha\Image.php

You will find below functions in this file which can be used to customize captcha image.

     /**
     * Set dot noise level
     *
     * @param int $dotNoiseLevel
     * @return Zend_Captcha_Image
     */
    public function setDotNoiseLevel ($dotNoiseLevel)
    {
        $this->_dotNoiseLevel = $dotNoiseLevel;
        return $this;
    }

    /**
     * Set line noise level
     *
     * @param int $lineNoiseLevel
     * @return Zend_Captcha_Image
     */
    public function setLineNoiseLevel ($lineNoiseLevel)
    {
        $this->_lineNoiseLevel = $lineNoiseLevel;
        return $this;
    }

you can change the values of this function from line number 122 and 129 .

/**
 * Number of noise dots on image
 * Used twice - before and after transform
 *
 * @var int
 */
protected $_dotNoiseLevel = 100;
/**
 * Number of noise lines on image
 * Used twice - before and after transform
 *
 * @var int
 */
protected $_lineNoiseLevel = 5;
  • Thanks Dinesh for sharing this. It will be better if you add a new question and post this answer as the answer. It will be helpful for those who are looking for it. – Jaimin Sutariya Mar 7 '17 at 5:20

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.