|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
------------------------------------------------------------------------- |
|
4
|
|
|
ADSLIGHT 2 : Module for Xoops |
|
5
|
|
|
|
|
6
|
|
|
Redesigned and ameliorate By Luc Bizet user at www.frxoops.org |
|
7
|
|
|
Started with the Classifieds module and made MANY changes |
|
8
|
|
|
Website : http://www.luc-bizet.fr |
|
9
|
|
|
Contact : [email protected] |
|
10
|
|
|
------------------------------------------------------------------------- |
|
11
|
|
|
Original credits below Version History |
|
12
|
|
|
########################################################################## |
|
13
|
|
|
# Classified Module for Xoops # |
|
14
|
|
|
# By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com # |
|
15
|
|
|
# Started with the MyAds module and made MANY changes # |
|
16
|
|
|
########################################################################## |
|
17
|
|
|
Original Author: Pascal Le Boustouller |
|
18
|
|
|
Author Website : [email protected] |
|
19
|
|
|
Licence Type : GPL |
|
20
|
|
|
------------------------------------------------------------------------- |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class GD |
|
25
|
|
|
*/ |
|
26
|
|
|
class GD |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
public $image; |
|
29
|
|
|
public $width; |
|
30
|
|
|
public $height; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param $location |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct($location) |
|
36
|
|
|
{ |
|
37
|
|
|
$imageinfo = @getimagesize($location) || exit('Unknown picture'); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$this->width = $imageinfo['0']; |
|
40
|
|
|
$this->height = $imageinfo['1']; |
|
41
|
|
|
|
|
42
|
|
|
switch ($imageinfo['2']) { |
|
43
|
|
|
case '1': |
|
44
|
|
|
$this->image = imagecreatefromgif($location); |
|
45
|
|
|
break; |
|
46
|
|
|
|
|
47
|
|
|
case '2': |
|
48
|
|
|
$this->image = imagecreatefromjpeg($location); |
|
49
|
|
|
break; |
|
50
|
|
|
|
|
51
|
|
|
case '3': |
|
52
|
|
|
$this->image = imagecreatefrompng($location); |
|
53
|
|
|
break; |
|
54
|
|
|
|
|
55
|
|
|
default: |
|
56
|
|
|
exit('Unknown file format'); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param $sizex |
|
62
|
|
|
* @param $sizey |
|
63
|
|
|
*/ |
|
64
|
|
|
public function resize($sizex, $sizey) |
|
65
|
|
|
{ |
|
66
|
|
|
$org = round($this->width / $this->height, 2); |
|
67
|
|
|
$new = round($sizex / $sizey, 2); |
|
68
|
|
|
|
|
69
|
|
|
if ($new > $org) { |
|
70
|
|
|
$sizex = round($this->width / ($this->height / $sizey), 0); |
|
71
|
|
|
$sizey = $sizey; |
|
|
|
|
|
|
72
|
|
|
} else { |
|
73
|
|
|
$sizex = $sizex; |
|
|
|
|
|
|
74
|
|
|
$sizey = round($this->height / ($this->width / $sizex), 0); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$resized = imagecreatetruecolor($sizex, $sizey); |
|
78
|
|
|
imagecopyresampled($resized, $this->image, 0, 0, 0, 0, $sizex, $sizey, $this->width, $this->height); |
|
79
|
|
|
|
|
80
|
|
|
$this->image = $resized; |
|
81
|
|
|
$this->width = $sizex; |
|
82
|
|
|
$this->height = $sizey; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param $color |
|
87
|
|
|
* |
|
88
|
|
|
* @return array |
|
|
|
|
|
|
89
|
|
|
*/ |
|
90
|
|
|
public function make_color($color) |
|
91
|
|
|
{ |
|
92
|
|
|
$rgb = array(); |
|
93
|
|
|
|
|
94
|
|
|
if (is_array($color) && count($color) == '3') { |
|
95
|
|
|
$rgb['r'] = $color['0']; |
|
96
|
|
|
$rgb['g'] = $color['1']; |
|
97
|
|
|
$rgb['b'] = $color['2']; |
|
98
|
|
|
} elseif (preg_match('/^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i', $color, $results)) { |
|
99
|
|
|
$rgb['r'] = hexdec($results['1']); |
|
100
|
|
|
$rgb['g'] = hexdec($results['2']); |
|
101
|
|
|
$rgb['b'] = hexdec($results['3']); |
|
102
|
|
|
} else { |
|
103
|
|
|
exit('Unknown color'); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
foreach (array('r', 'g', 'b') as $value) { |
|
107
|
|
|
if (!array_key_exists($value, $rgb) || $rgb[$value] < 0 || $rgb[$value] > 255 || !is_numeric($rgb[$value])) { |
|
108
|
|
|
exit('Wrong color'); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $rgb; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param $width |
|
117
|
|
|
* @param $color |
|
118
|
|
|
*/ |
|
119
|
|
|
public function add_border($width, $color) |
|
120
|
|
|
{ |
|
121
|
|
|
$rgb = $this->make_color($color); |
|
122
|
|
|
$allocate = imagecolorallocate($this->image, $rgb['r'], $rgb['g'], $rgb['b']); |
|
123
|
|
|
|
|
124
|
|
|
if ($width < 1) { |
|
125
|
|
|
exit('Wrong frame width'); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$sizex = $this->width + (2 * $width); |
|
129
|
|
|
$sizey = $this->height + (2 * $width); |
|
130
|
|
|
$new_image = imagecreatetruecolor($sizex, $sizey); |
|
131
|
|
|
|
|
132
|
|
|
imagefill($new_image, 0, 0, $allocate); |
|
133
|
|
|
imagecopyresampled($new_image, $this->image, $width, $width, 0, 0, $this->width, $this->height, $this->width, $this->height); |
|
134
|
|
|
|
|
135
|
|
|
$this->image = $new_image; |
|
136
|
|
|
$this->width = $sizex; |
|
137
|
|
|
$this->height = $sizey; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param $text |
|
142
|
|
|
* @param $font |
|
143
|
|
|
* @param $color |
|
144
|
|
|
* @param $x |
|
145
|
|
|
* @param $y |
|
146
|
|
|
*/ |
|
147
|
|
|
public function add_text($text, $font, $color, $x, $y) |
|
|
|
|
|
|
148
|
|
|
{ |
|
149
|
|
|
if ($font < 1 || $font > 5) { |
|
150
|
|
|
exit('Wrong font'); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
$rgb = $this->make_color($color); |
|
154
|
|
|
$allocate = imagecolorallocate($this->image, $rgb['r'], $rgb['g'], $rgb['b']); |
|
|
|
|
|
|
155
|
|
|
$text_width = imagefontwidth($font) * strlen($text); |
|
|
|
|
|
|
156
|
|
|
$text_height = imagefontheight($font); |
|
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
//Dokoncaj |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @param $text |
|
163
|
|
|
* @param $size |
|
164
|
|
|
* @param $color |
|
165
|
|
|
* @param $x |
|
166
|
|
|
* @param $y |
|
167
|
|
|
* @param string $font |
|
168
|
|
|
*/ |
|
169
|
|
|
public function add_ttf_text($text, $size, $color, $x, $y, $font = './tahoma.ttf') |
|
170
|
|
|
{ |
|
171
|
|
|
if (!is_file($font)) { |
|
172
|
|
|
exit('Unknown font'); |
|
|
|
|
|
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
$rgb = $this->make_color($color); |
|
176
|
|
|
$allocate = imagecolorallocate($this->image, $rgb['r'], $rgb['g'], $rgb['b']); |
|
177
|
|
|
imagettftext($this->image, $size, 0, $x, $y, $allocate, $font, $text); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @param $location |
|
182
|
|
|
* @param string $quality |
|
183
|
|
|
*/ |
|
184
|
|
|
public function save($location, $quality = '80') |
|
185
|
|
|
{ |
|
186
|
|
|
imagejpeg($this->image, $location, $quality); |
|
187
|
|
|
imagedestroy($this->image); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.