From 1a2b3932aef6ebffcfb94239fec0c9ebd2618dd1 Mon Sep 17 00:00:00 2001 From: gongwen Date: Sun, 24 Sep 2023 14:01:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9php=E9=AB=98=E7=89=88?= =?UTF-8?q?=E6=9C=AC8.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/VerifyCode.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/VerifyCode.php b/src/VerifyCode.php index d007939..b60607c 100644 --- a/src/VerifyCode.php +++ b/src/VerifyCode.php @@ -111,27 +111,27 @@ private function writeCurve(): void { $px = $py = 0; // 曲线前部分 - $A = mt_rand(1, $this->conf->imageH / 2); // 振幅 - $b = mt_rand(-$this->conf->imageH / 4, $this->conf->imageH / 4); // Y轴方向偏移量 - $f = mt_rand(-$this->conf->imageH / 4, $this->conf->imageH / 4); // X轴方向偏移量 + $A = mt_rand(1, (int)($this->conf->imageH / 2)); // 振幅 + $b = mt_rand(-(int)($this->conf->imageH / 4), (int)($this->conf->imageH / 4)); // Y轴方向偏移量 + $f = mt_rand(-(int)($this->conf->imageH / 4), (int)($this->conf->imageH / 4)); // X轴方向偏移量 $T = mt_rand($this->conf->imageH, $this->conf->imageL * 2); // 周期 $w = (2 * M_PI) / $T; $px1 = 0; // 曲线横坐标起始位置 - $px2 = mt_rand($this->conf->imageL / 2, $this->conf->imageL * 0.8); // 曲线横坐标结束位置 + $px2 = mt_rand((int)($this->conf->imageL / 2), (int)($this->conf->imageL * 0.8)); // 曲线横坐标结束位置 for ($px = $px1; $px <= $px2; $px = $px + 1) { if (0 != $w) { $py = $A * sin($w * $px + $f) + $b + $this->conf->imageH / 2; // y = Asin(ωx+φ) + b $i = (int)($this->conf->fontSize / 5); while ($i > 0) { // 这里(while)循环画像素点比imagettftext和imagestring用字体大小一次画出(不用这while循环)性能要好很多 - imagesetpixel($this->imInstance, $px + $i, $py + $i, $this->conf->fontColor); + imagesetpixel($this->imInstance, (int)($px + $i), (int)($py + $i), $this->conf->fontColor); $i--; } } } // 曲线后部分 - $A = mt_rand(1, $this->conf->imageH / 2); // 振幅 - $f = mt_rand(-$this->conf->imageH / 4, $this->conf->imageH / 4); // X轴方向偏移量 + $A = mt_rand(1, (int)($this->conf->imageH / 2)); // 振幅 + $f = mt_rand(-(int)($this->conf->imageH / 4), (int)($this->conf->imageH / 4)); // X轴方向偏移量 $T = mt_rand($this->conf->imageH, $this->conf->imageL * 2); // 周期 $w = (2 * M_PI) / $T; $b = $py - $A * sin($w * $px + $f) - $this->conf->imageH / 2; @@ -142,7 +142,7 @@ private function writeCurve(): void $py = $A * sin($w * $px + $f) + $b + $this->conf->imageH / 2; // y = Asin(ωx+φ) + b $i = (int)($this->conf->fontSize / 5); while ($i > 0) { - imagesetpixel($this->imInstance, intval($px + $i), intval($py + $i), $this->conf->fontColor); + imagesetpixel($this->imInstance, (int)($px + $i), (int)($py + $i), $this->conf->fontColor); $i--; } }