Changing the style of captcha text
-
Hi,
i’ve tested your plugin and it’s working great. I currently wanted to re-design the captcha image, and I nailed.
But the code is inside of the plugins, which I believe it’s not recommend to do that, and I would like to modify it via theme functions.phpHere the screenshoot of the result:
This is the code that I changed /core/CaptchaImageGenerator.class.php line 28 – 77 :
/** * Generate the Captcha */ public function getImage() { // the captcha $captcha = $this->get(); // Create the image $image = imagecreate( 105, 30 ); // 125 imagecolorallocate( $image, 203, 14, 25 ); // Positioning $offsetLeft = 10; for ( $i = 0; $i < strlen( $captcha ); $i ++ ) { //imagettftext( $image, 20, rand( - 10, 10 ), $offsetLeft + ( ( $i == 0 ? 5 : 15 ) * $i ), 25, imagecolorallocate( $image, 200, 200, 200 ), $this->_font, $captcha[ $i ] ); imagettftext( $image, 16, rand( - 15, 15 ), $offsetLeft + ( ( $i == 0 ? 5 : 15 ) * $i ), 25, imagecolorallocate( $image, 255, 255, 255 ), $this->_font, $captcha[ $i ] ); } ob_start(); imagepng($image); $image = ob_get_contents(); ob_end_clean(); return '<img src="data:image/png;base64,'.base64_encode($image).'"/>'; } public static function validate($captcha_code, $captcha_hash){ $Captcha = Captcha::getByHash($captcha_hash); if(!$Captcha || $captcha_code != $Captcha->getCode()){ return false; } return true; } public static function get_form_field($fieldname, $classes = ''){ $Captcha = new CaptchaImageGenerator(6); $CaptchaItem = __('','f12-captcha').' '.$Captcha->getImage(); $CaptchaSession = new Captcha(); $CaptchaSession->setCode($Captcha->get()); $CaptchaSession->save(); $captcha = '<input type="hidden" id="'.esc_attr($fieldname).'_hash" name="'.esc_attr($fieldname).'_hash" value="' . esc_attr($CaptchaSession->getHash()) . '"/>'; $captcha .= '<div class="'.$classes.' ars-bbcp"><label>'.$CaptchaItem.'</label><br><input type="text" id="'.esc_attr($fieldname).'" name="' . esc_attr($fieldname) . '" placeholder="'.__('captcha','f12-captcha').'" value="" /></div>'; return $captcha; } }
As my pre-question, is it possible to move the modification code to the theme functions.php? Maybe I overlook the code and you already provide this feature.
I’m gladly open to help you to create this functionality and make changing the color text & background captcha easier ??</img>.
Thank you.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Changing the style of captcha text’ is closed to new replies.