source: trunk/Packages/Common/Image.php

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