HuasoFoundries /
jpgraph
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * JPGraph v4.0.3 |
||||
| 5 | */ |
||||
| 6 | |||||
| 7 | namespace Amenadiel\JpGraph\Image; |
||||
| 8 | |||||
| 9 | /** |
||||
| 10 | * // File: JPGRAPH_ANTISPAM.PHP |
||||
| 11 | * // Description: Genarate anti-spam challenge |
||||
| 12 | * // Created: 2004-10-07 |
||||
| 13 | * // Ver: $Id: jpgraph_antispam.php 1106 2009-02-22 20:16:35Z ljp $ |
||||
| 14 | * // |
||||
| 15 | * // Copyright (c) Asial Corporation. All rights reserved. |
||||
| 16 | */ |
||||
| 17 | class AntiSpam |
||||
| 18 | { |
||||
| 19 | private $iData = ''; |
||||
| 20 | private $iDD; |
||||
| 21 | |||||
| 22 | 1 | public function __construct($aData = '') |
|||
| 23 | { |
||||
| 24 | 1 | $this->iData = $aData; |
|||
| 25 | 1 | $this->iDD = new HandDigits(); |
|||
| 26 | 1 | } |
|||
| 27 | |||||
| 28 | public function Set($aData) |
||||
| 29 | { |
||||
| 30 | $this->iData = $aData; |
||||
| 31 | } |
||||
| 32 | |||||
| 33 | 1 | public function Rand($aLen) |
|||
| 34 | { |
||||
| 35 | 1 | $d = ''; |
|||
| 36 | 1 | for ($i = 0; $i < $aLen; ++$i) { |
|||
| 37 | 1 | if (rand(0, 9) < 6) { |
|||
| 38 | // Digits |
||||
| 39 | 1 | $d .= chr(ord('1') + rand(0, 8)); |
|||
| 40 | } else { |
||||
| 41 | // Letters |
||||
| 42 | do { |
||||
| 43 | 1 | $offset = rand(0, 25); |
|||
| 44 | 1 | } while ($offset == 14); |
|||
| 45 | 1 | $d .= chr(ord('a') + $offset); |
|||
| 46 | } |
||||
| 47 | } |
||||
| 48 | 1 | $this->iData = $d; |
|||
| 49 | |||||
| 50 | 1 | return $d; |
|||
| 51 | } |
||||
| 52 | |||||
| 53 | 1 | public function Stroke() |
|||
| 54 | { |
||||
| 55 | 1 | $n = strlen($this->iData); |
|||
| 56 | 1 | if ($n == 0) { |
|||
| 57 | return false; |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | 1 | for ($i = 0; $i < $n; ++$i) { |
|||
| 61 | 1 | if ($this->iData[$i] === '0' || strtolower($this->iData[$i]) === 'o') { |
|||
| 62 | return false; |
||||
| 63 | } |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | 1 | $img = @imagecreatetruecolor($n * $this->iDD->iWidth, $this->iDD->iHeight); |
|||
| 67 | 1 | if ($img < 1) { |
|||
| 68 | return false; |
||||
| 69 | } |
||||
| 70 | |||||
| 71 | 1 | $start = 0; |
|||
| 72 | 1 | for ($i = 0; $i < $n; ++$i) { |
|||
| 73 | 1 | $dimg = imagecreatefromstring(base64_decode($this->iDD->chars[strtolower($this->iData[$i])][1], true)); |
|||
| 74 | 1 | imagecopy($img, $dimg, $start, 0, 0, 0, imagesx($dimg), $this->iDD->iHeight); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 75 | 1 | $start += imagesx($dimg); |
|||
| 76 | } |
||||
| 77 | 1 | $resimg = @imagecreatetruecolor($start + 4, $this->iDD->iHeight + 4); |
|||
| 78 | 1 | if ($resimg < 1) { |
|||
| 79 | return false; |
||||
| 80 | } |
||||
| 81 | |||||
| 82 | 1 | imagecopy($resimg, $img, 2, 2, 0, 0, $start, $this->iDD->iHeight); |
|||
|
0 ignored issues
–
show
It seems like
$img can also be of type false; however, parameter $src_im of imagecopy() does only seem to accept GdImage|resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 83 | 1 | header('Content-type: image/jpeg'); |
|||
| 84 | 1 | imagejpeg($resimg); |
|||
|
0 ignored issues
–
show
It seems like
$resimg can also be of type false; however, parameter $image of imagejpeg() does only seem to accept GdImage|resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 85 | |||||
| 86 | 1 | return true; |
|||
| 87 | } |
||||
| 88 | } |
||||
| 89 |