Иногда дизайн страницы требует размещать капчу на соответствующем фоне. Стандартная капча Битрикса при всем множестве настроек не дает такой возможности.[spoiler] Класс CCaptcha можно легко расширить и указывать фон капчи из файла:
class CBGCaptcha extends CCaptcha
{
private $bgImage = '';
public function SetBgImage($imgPath) {
if(file_exists($imgPath)) {
$bgImgProp = getimagesize($imgPath);
$this->bgImage = $imgPath;
$this->imageWidth = $bgImgProp[0];
$this->imageHeight = $bgImgProp[1];
}
}
function InitImage($width = false, $height = false)
{
if(!$width)
$width = $this->imageWidth;
if(!$height)
$height = $this->imageHeight;
$image = false;
if(strlen($this->bgImage) > 0) {
$image = @imagecreatefromjpeg($this->bgImage);
}
if(!$image) {
$image = imagecreatetruecolor($width, $height);
if(!$this->arRealBGColor)
{
$this->arRealBGColor = $this->GetColor($this->arBGColor);
}
$bgColor = imagecolorallocate($image, $this->arRealBGColor[0], $this->arRealBGColor[1], $this->arRealBGColor[2]);
imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), $bgColor);
}
return $image;
}
} |
Далее создаем новый скрипт капчи, аналогично /bitrix/tools/captcha.php установив картинку, которую будем использовать в качестве фона (в данном примере возможно только использовать .jpg):
$cpt = new CBGCaptcha();
$cpt->SetBgImage($_SERVER["DOCUMENT_ROOT"]."/realsteel/bg_captcha.jpg"); |