Optimize formatting for Symfony coding standards
This commit is contained in:
parent
9fc82c8453
commit
fef3e306fd
|
@ -136,46 +136,45 @@ class CaptchaGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write CAPTCHA text
|
// Write CAPTCHA text
|
||||||
$size = $width/strlen($captchaValue);
|
$size = $width / strlen($captchaValue);
|
||||||
$font = $options['font'];
|
$font = $options['font'];
|
||||||
$box = imagettfbbox($size, 0, $font, $captchaValue);
|
$box = imagettfbbox($size, 0, $font, $captchaValue);
|
||||||
$txt_width = $box[2] - $box[0];
|
$textWidth = $box[2] - $box[0];
|
||||||
$txt_height = $box[1] - $box[7];
|
$textHeight = $box[1] - $box[7];
|
||||||
|
|
||||||
imagettftext($i, $size, 0, ($width-$txt_width)/2, ($height-$txt_height)/2+$size, $col, $font, $captchaValue);
|
imagettftext($i, $size, 0, ($width - $textWidth) / 2, ($height - $textHeight) / 2 + $size, $col, $font, $captchaValue);
|
||||||
|
|
||||||
// Distort the image
|
// Distort the image
|
||||||
$X = $this->rand(0, $width);
|
$X = $this->rand(0, $width);
|
||||||
$Y = $this->rand(0, $height);
|
$Y = $this->rand(0, $height);
|
||||||
$Phase=$this->rand(0,10);
|
$phase = $this->rand(0, 10);
|
||||||
$Scale = 1.3 + $this->rand(0,10000)/30000;
|
$scale = 1.3 + $this->rand(0, 10000) / 30000;
|
||||||
$Amp=1+$this->rand(0,1000)/1000;
|
|
||||||
$out = imagecreatetruecolor($width, $height);
|
$out = imagecreatetruecolor($width, $height);
|
||||||
|
|
||||||
for ($x=0; $x<$width; $x++) {
|
for ($x = 0; $x < $width; $x++) {
|
||||||
for ($y=0; $y<$height; $y++) {
|
for ($y = 0; $y < $height; $y++) {
|
||||||
$Vx=$x-$X;
|
$Vx = $x - $X;
|
||||||
$Vy=$y-$Y;
|
$Vy = $y - $Y;
|
||||||
$Vn=sqrt($Vx*$Vx+$Vy*$Vy);
|
$Vn = sqrt($Vx * $Vx + $Vy * $Vy);
|
||||||
|
|
||||||
if ($Vn!=0) {
|
if ($Vn != 0) {
|
||||||
$Vn2=$Vn+4*sin($Vn/8);
|
$Vn2 = $Vn + 4 * sin($Vn / 8);
|
||||||
$nX=$X+($Vx*$Vn2/$Vn);
|
$nX = $X + ($Vx * $Vn2 / $Vn);
|
||||||
$nY=$Y+($Vy*$Vn2/$Vn);
|
$nY = $Y + ($Vy * $Vn2 / $Vn);
|
||||||
} else {
|
} else {
|
||||||
$nX=$X;
|
$nX = $X;
|
||||||
$nY=$Y;
|
$nY = $Y;
|
||||||
}
|
}
|
||||||
$nY = $nY+$Scale*sin($Phase + $nX*0.2);
|
$nY = $nY + $scale * sin($phase + $nX * 0.2);
|
||||||
|
|
||||||
$p = $this->bilinearInterpolate($nX-floor($nX), $nY-floor($nY),
|
$p = $this->bilinearInterpolate($nX - floor($nX), $nY - floor($nY),
|
||||||
$this->getCol($i,floor($nX),floor($nY)),
|
$this->getCol($i, floor($nX), floor($nY)),
|
||||||
$this->getCol($i,ceil($nX),floor($nY)),
|
$this->getCol($i, ceil($nX), floor($nY)),
|
||||||
$this->getCol($i,floor($nX),ceil($nY)),
|
$this->getCol($i, floor($nX), ceil($nY)),
|
||||||
$this->getCol($i,ceil($nX),ceil($nY)));
|
$this->getCol($i, ceil($nX), ceil($nY)));
|
||||||
|
|
||||||
if ($p==0) {
|
if ($p == 0) {
|
||||||
$p=0xFFFFFF;
|
$p = 0xFFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
imagesetpixel($out, $x, $y, $p);
|
imagesetpixel($out, $x, $y, $p);
|
||||||
|
@ -302,7 +301,7 @@ class CaptchaGenerator
|
||||||
{
|
{
|
||||||
$L = imagesx($image);
|
$L = imagesx($image);
|
||||||
$H = imagesy($image);
|
$H = imagesy($image);
|
||||||
if ($x<0 || $x>=$L || $y<0 || $y>=$H) {
|
if ($x < 0 || $x >= $L || $y < 0 || $y >= $H) {
|
||||||
return 0xFFFFFF;
|
return 0xFFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,7 @@ class CaptchaValidator
|
||||||
$code = $form->getData();
|
$code = $form->getData();
|
||||||
$expectedCode = $this->getExpectedCode();
|
$expectedCode = $this->getExpectedCode();
|
||||||
|
|
||||||
if (!($code && is_string($code)
|
if (!($code && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) {
|
||||||
&& ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) {
|
|
||||||
$form->addError(new FormError($this->invalidMessage));
|
$form->addError(new FormError($this->invalidMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue