[746] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | define('COLOR_BLACK', 0x000000);
|
---|
| 4 | define('COLOR_RED', 0xff0000);
|
---|
| 5 | define('COLOR_GREEN', 0x00ff00);
|
---|
| 6 | define('COLOR_BLUE', 0x0000ff);
|
---|
| 7 | define('COLOR_WHITE', 0xffffff);
|
---|
| 8 |
|
---|
| 9 | class Font
|
---|
| 10 | {
|
---|
[887] | 11 | public int $Size;
|
---|
| 12 | public string $FileName;
|
---|
| 13 | public int $Color;
|
---|
[746] | 14 |
|
---|
| 15 | function __construct()
|
---|
| 16 | {
|
---|
| 17 | $this->Color = COLOR_BLACK;
|
---|
| 18 | $this->FileName = '../../Common/Fonts/FreeSans.ttf';
|
---|
| 19 | $this->Size = 10;
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | class Pen
|
---|
| 24 | {
|
---|
[887] | 25 | public int $Color;
|
---|
| 26 | public int $X;
|
---|
| 27 | public int $Y;
|
---|
[746] | 28 |
|
---|
| 29 | function __construct()
|
---|
| 30 | {
|
---|
| 31 | $this->Color = COLOR_BLACK;
|
---|
| 32 | $this->X = 0;
|
---|
| 33 | $this->Y = 0;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | class Brush
|
---|
| 39 | {
|
---|
[887] | 40 | public int $Color;
|
---|
[746] | 41 |
|
---|
| 42 | function __construct()
|
---|
| 43 | {
|
---|
| 44 | $this->Color = COLOR_BLACK;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | class Image
|
---|
| 50 | {
|
---|
[887] | 51 | public $Image;
|
---|
| 52 | public int $Type;
|
---|
| 53 | public Font $Font;
|
---|
| 54 | public Pen $Pen;
|
---|
| 55 | public Brush $Brush;
|
---|
[746] | 56 |
|
---|
| 57 | function __construct()
|
---|
| 58 | {
|
---|
| 59 | $this->Image = imagecreatetruecolor(1, 1);
|
---|
| 60 | $this->Type = IMAGETYPE_PNG;
|
---|
| 61 | $this->Pen = new Pen();
|
---|
| 62 | $this->Font = new Font();
|
---|
| 63 | $this->Brush = new Brush();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[887] | 66 | function SaveToFile(string $FileName): void
|
---|
[746] | 67 | {
|
---|
[873] | 68 | if ($this->Type == IMAGETYPE_JPEG)
|
---|
[746] | 69 | {
|
---|
| 70 | imagejpeg($this->Image, $FileName);
|
---|
| 71 | } else
|
---|
[873] | 72 | if ($this->Type == IMAGETYPE_GIF)
|
---|
[746] | 73 | {
|
---|
[873] | 74 | imagegif ($this->Image, $FileName);
|
---|
[746] | 75 | } else
|
---|
[873] | 76 | if ($this->Type == IMAGETYPE_PNG)
|
---|
[746] | 77 | {
|
---|
| 78 | imagepng($this->Image, $FileName);
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[887] | 82 | function LoadFromFile(string $FileName): void
|
---|
[746] | 83 | {
|
---|
| 84 | $ImageInfo = getimagesize($FileName);
|
---|
| 85 | $this->Type = $ImageInfo[2];
|
---|
[873] | 86 | if ($this->Type == IMAGETYPE_JPEG)
|
---|
[746] | 87 | {
|
---|
| 88 | $this->Image = imagecreatefromjpeg($FileName);
|
---|
| 89 | } else
|
---|
[873] | 90 | if ($this->Type == IMAGETYPE_GIF)
|
---|
[746] | 91 | {
|
---|
[873] | 92 | $this->Image = imagecreatefromgif ($FileName);
|
---|
[746] | 93 | } else
|
---|
[873] | 94 | if ( $this->Type == IMAGETYPE_PNG)
|
---|
[746] | 95 | {
|
---|
| 96 | $this->Image = imagecreatefrompng($FileName);
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[887] | 100 | function SetSize(int $Width, int $Height): void
|
---|
[746] | 101 | {
|
---|
| 102 | $NewImage = imagecreatetruecolor($Width, $Height);
|
---|
| 103 | imagecopy($NewImage, $this->Image, 0, 0, 0, 0, $this->GetWidth(), $this->GetHeight());
|
---|
| 104 | imagedestroy($this->Image);
|
---|
| 105 | $this->Image = $NewImage;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[887] | 108 | function GetWidth(): int
|
---|
[746] | 109 | {
|
---|
[874] | 110 | return imagesx($this->Image);
|
---|
[746] | 111 | }
|
---|
| 112 |
|
---|
[887] | 113 | function GetHeight(): int
|
---|
[746] | 114 | {
|
---|
[874] | 115 | return imagesy($this->Image);
|
---|
[746] | 116 | }
|
---|
| 117 |
|
---|
[887] | 118 | function TextOut(int $X, int $Y, string $Text): void
|
---|
[746] | 119 | {
|
---|
| 120 | imagettftext($this->Image, $this->Font->Size, 0, $X, $Y, $this->ConvertColor($this->Font->Color), $this->Font->FileName, $Text);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[887] | 123 | function ConvertColor(int $Color): int
|
---|
[746] | 124 | {
|
---|
[874] | 125 | return imagecolorallocate($this->Image, ($Color >> 16) & 0xff, ($Color >> 8) & 0xff, $Color & 0xff);
|
---|
[746] | 126 | }
|
---|
| 127 |
|
---|
[887] | 128 | function FillRect(int $X1, int $Y1, int $X2, int $Y2): void
|
---|
[746] | 129 | {
|
---|
| 130 | imagefilledrectangle($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Brush->Color));
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[887] | 133 | function Line(int $X1, int $Y1, int $X2, int $Y2): void
|
---|
[746] | 134 | {
|
---|
| 135 | imageline($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Pen->Color));
|
---|
| 136 | }
|
---|
| 137 | }
|
---|