suricate-php /
framework
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Suricate; |
||||
| 6 | |||||
| 7 | class ImageFont |
||||
| 8 | { |
||||
| 9 | const FONTTYPE_INTERNAL = 1; |
||||
| 10 | const FONTTYPE_TTF = 2; |
||||
| 11 | |||||
| 12 | private $color = [0, 0, 0]; |
||||
| 13 | private $text; |
||||
| 14 | private $angle = 0; |
||||
| 15 | private $size = 8; |
||||
| 16 | private $fontType; |
||||
| 17 | private $font; |
||||
| 18 | |||||
| 19 | public function __construct($text = '') |
||||
| 20 | { |
||||
| 21 | $this->text = $text; |
||||
| 22 | } |
||||
| 23 | |||||
| 24 | public function font($fontFile) |
||||
| 25 | { |
||||
| 26 | $this->fontType = is_int($fontFile) |
||||
| 27 | ? self::FONTTYPE_INTERNAL |
||||
| 28 | : self::FONTTYPE_TTF; |
||||
| 29 | |||||
| 30 | $this->font = $fontFile; |
||||
| 31 | } |
||||
| 32 | |||||
| 33 | public function size($size) |
||||
| 34 | { |
||||
| 35 | $this->size = $size; |
||||
| 36 | |||||
| 37 | return $this; |
||||
| 38 | } |
||||
| 39 | |||||
| 40 | public function angle($angle) |
||||
| 41 | { |
||||
| 42 | $this->angle = $angle; |
||||
| 43 | |||||
| 44 | return $this; |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | public function color(array $color) |
||||
| 48 | { |
||||
| 49 | $this->color = $color; |
||||
| 50 | |||||
| 51 | return $this; |
||||
| 52 | } |
||||
| 53 | |||||
| 54 | private function createColor($image) |
||||
| 55 | { |
||||
| 56 | return imagecolorallocate( |
||||
| 57 | $image, |
||||
| 58 | $this->color[0], |
||||
| 59 | $this->color[1], |
||||
| 60 | $this->color[2] |
||||
| 61 | ); |
||||
| 62 | } |
||||
| 63 | |||||
| 64 | public function align($align) |
||||
|
0 ignored issues
–
show
|
|||||
| 65 | { |
||||
| 66 | } |
||||
| 67 | |||||
| 68 | public function text($text) |
||||
| 69 | { |
||||
| 70 | $this->text = $text; |
||||
| 71 | |||||
| 72 | return $this; |
||||
| 73 | } |
||||
| 74 | |||||
| 75 | public function valign($align) |
||||
|
0 ignored issues
–
show
The parameter
$align is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 76 | { |
||||
| 77 | } |
||||
| 78 | |||||
| 79 | /** |
||||
| 80 | * Get text bounding box |
||||
| 81 | * |
||||
| 82 | * @return array|false |
||||
| 83 | */ |
||||
| 84 | public function getBoundingBox() |
||||
| 85 | { |
||||
| 86 | return imageftbbox($this->size, $this->angle, $this->font, $this->text); |
||||
| 87 | } |
||||
| 88 | |||||
| 89 | public function apply(&$image, $x = 0, $y = 0) |
||||
| 90 | { |
||||
| 91 | $colorResource = $this->createColor($image); |
||||
| 92 | |||||
| 93 | if ($this->fontType == self::FONTTYPE_INTERNAL) { |
||||
| 94 | imagestring( |
||||
| 95 | $image, |
||||
| 96 | $this->font, |
||||
| 97 | $x, |
||||
| 98 | $y, |
||||
| 99 | $this->text, |
||||
| 100 | $colorResource |
||||
| 101 | ); |
||||
| 102 | return; |
||||
| 103 | } |
||||
| 104 | imagettftext( |
||||
| 105 | $image, |
||||
| 106 | $this->size, |
||||
| 107 | $this->angle, |
||||
| 108 | $x, |
||||
| 109 | $y, |
||||
| 110 | $colorResource, |
||||
| 111 | $this->font, |
||||
| 112 | $this->text |
||||
| 113 | ); |
||||
| 114 | } |
||||
| 115 | } |
||||
| 116 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.