@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @return boolean |
136 | 136 | */ |
137 | 137 | public static function isEncryptionCompatible() { |
138 | - return function_exists('mcrypt_encrypt') && function_exists('mcrypt_encrypt') && function_exists('mcrypt_decrypt'); |
|
138 | + return function_exists('mcrypt_encrypt') && function_exists('mcrypt_encrypt') && function_exists('mcrypt_decrypt'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @return string Encrypted and encoded text |
147 | 147 | */ |
148 | 148 | public static function encryptToSafeBase64($data){ |
149 | - if(!self::isEncryptionCompatible()) |
|
150 | - throw new \Exception('MCrypt PHP extension is required to use encryption.'); |
|
149 | + if(!self::isEncryptionCompatible()) |
|
150 | + throw new \Exception('MCrypt PHP extension is required to use encryption.'); |
|
151 | 151 | |
152 | 152 | $key = 'STANDARDKEYIFNOSERVER'; |
153 | 153 | if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @return string Decrypted text |
170 | 170 | */ |
171 | 171 | public static function decryptFromSafeBase64($encrypted){ |
172 | - if(!self::isEncryptionCompatible()) |
|
173 | - throw new \Exception('MCrypt PHP extension is required to use encryption.'); |
|
172 | + if(!self::isEncryptionCompatible()) |
|
173 | + throw new \Exception('MCrypt PHP extension is required to use encryption.'); |
|
174 | 174 | |
175 | 175 | $key = 'STANDARDKEYIFNOSERVER'; |
176 | 176 | if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public static function encodeFileSystemToUtf8($string){ |
199 | 199 | if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
200 | - return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
200 | + return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
201 | 201 | } |
202 | 202 | return $string; |
203 | 203 | } |
@@ -262,20 +262,20 @@ discard block |
||
262 | 262 | * @return boolean|string Is supported? |
263 | 263 | */ |
264 | 264 | public static function isImageTypeSupported($reqtype) { |
265 | - $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
|
266 | - $reqtype = strtolower($reqtype); |
|
265 | + $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
|
266 | + $reqtype = strtolower($reqtype); |
|
267 | 267 | |
268 | - if (empty($supportByGD[$reqtype])) { |
|
269 | - return false; |
|
270 | - } |
|
268 | + if (empty($supportByGD[$reqtype])) { |
|
269 | + return false; |
|
270 | + } |
|
271 | 271 | |
272 | - $type = $supportByGD[$reqtype]; |
|
272 | + $type = $supportByGD[$reqtype]; |
|
273 | 273 | |
274 | - if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { |
|
275 | - return $type; |
|
276 | - } |
|
274 | + if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { |
|
275 | + return $type; |
|
276 | + } |
|
277 | 277 | |
278 | - return false; |
|
278 | + return false; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | } |
@@ -22,54 +22,54 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class ImageBuilder { |
24 | 24 | |
25 | - /** |
|
26 | - * Reference media |
|
27 | - * @var Media $media |
|
28 | - */ |
|
29 | - protected $media; |
|
25 | + /** |
|
26 | + * Reference media |
|
27 | + * @var Media $media |
|
28 | + */ |
|
29 | + protected $media; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Use TTF font |
|
33 | - * @var bool $use_ttf |
|
34 | - */ |
|
35 | - protected $use_ttf; |
|
31 | + /** |
|
32 | + * Use TTF font |
|
33 | + * @var bool $use_ttf |
|
34 | + */ |
|
35 | + protected $use_ttf; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Expiration offset. Default is one day. |
|
39 | - * @var int $expire_offset |
|
40 | - */ |
|
41 | - protected $expire_offset; |
|
37 | + /** |
|
38 | + * Expiration offset. Default is one day. |
|
39 | + * @var int $expire_offset |
|
40 | + */ |
|
41 | + protected $expire_offset; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Should the certificate display a watermark |
|
45 | - * @var bool $show_watermark |
|
46 | - */ |
|
47 | - protected $show_watermark; |
|
43 | + /** |
|
44 | + * Should the certificate display a watermark |
|
45 | + * @var bool $show_watermark |
|
46 | + */ |
|
47 | + protected $show_watermark; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Maximum watermark font size. Default is 18. |
|
51 | - * @var int $font_max_size |
|
52 | - */ |
|
53 | - protected $font_max_size; |
|
49 | + /** |
|
50 | + * Maximum watermark font size. Default is 18. |
|
51 | + * @var int $font_max_size |
|
52 | + */ |
|
53 | + protected $font_max_size; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Watermark font color, in hexadecimal. Default is #4D6DF3. |
|
57 | - * @var string $font_color |
|
58 | - */ |
|
59 | - protected $font_color; |
|
55 | + /** |
|
56 | + * Watermark font color, in hexadecimal. Default is #4D6DF3. |
|
57 | + * @var string $font_color |
|
58 | + */ |
|
59 | + protected $font_color; |
|
60 | 60 | |
61 | 61 | /** |
62 | - * Contructor for ImageBuilder |
|
63 | - * |
|
64 | - * @param Media|null $media Reference media object |
|
65 | - */ |
|
62 | + * Contructor for ImageBuilder |
|
63 | + * |
|
64 | + * @param Media|null $media Reference media object |
|
65 | + */ |
|
66 | 66 | public function __construct(Media $media = null){ |
67 | - $this->media = $media; |
|
68 | - $this->use_ttf = function_exists('imagettftext'); |
|
69 | - $this->expire_offset = 3600 * 24; |
|
70 | - $this->show_watermark = true; |
|
71 | - $this->font_max_size = 18; |
|
72 | - $this->font_color = '#4D6DF3'; |
|
67 | + $this->media = $media; |
|
68 | + $this->use_ttf = function_exists('imagettftext'); |
|
69 | + $this->expire_offset = 3600 * 24; |
|
70 | + $this->show_watermark = true; |
|
71 | + $this->font_max_size = 18; |
|
72 | + $this->font_color = '#4D6DF3'; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return int |
79 | 79 | */ |
80 | 80 | public function getExpireOffset() { |
81 | - return $this->expire_offset; |
|
81 | + return $this->expire_offset; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * @return ImageBuilder |
89 | 89 | */ |
90 | 90 | public function setExpireOffset($expireOffset) { |
91 | - if($expireOffset) $this->expire_offset = $expireOffset; |
|
92 | - return $this; |
|
91 | + if($expireOffset) $this->expire_offset = $expireOffset; |
|
92 | + return $this; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @return bool |
99 | 99 | */ |
100 | 100 | public function isShowWatermark() { |
101 | - return $this->show_watermark; |
|
101 | + return $this->show_watermark; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @return ImageBuilder |
109 | 109 | */ |
110 | 110 | public function setShowWatermark($show_watermark) { |
111 | - if(!is_null($show_watermark)) $this->show_watermark = $show_watermark; |
|
112 | - return $this; |
|
111 | + if(!is_null($show_watermark)) $this->show_watermark = $show_watermark; |
|
112 | + return $this; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @return ImageBuilder |
120 | 120 | */ |
121 | 121 | public function setFontMaxSize($font_max_size) { |
122 | - if($font_max_size) $this->font_max_size = $font_max_size; |
|
123 | - return $this; |
|
122 | + if($font_max_size) $this->font_max_size = $font_max_size; |
|
123 | + return $this; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @return ImageBuilder |
131 | 131 | */ |
132 | 132 | public function setFontColor($font_color) { |
133 | - if($font_color) $this->font_color = $font_color; |
|
134 | - return $this; |
|
133 | + if($font_color) $this->font_color = $font_color; |
|
134 | + return $this; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,134 +139,134 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function render(){ |
141 | 141 | |
142 | - if (!$this->media || !$this->media->canShow()) { |
|
143 | - Log::addMediaLog('Image Builder error: >' . I18N::translate('Missing or private media object.')); |
|
144 | - $this->renderError(); |
|
145 | - } |
|
142 | + if (!$this->media || !$this->media->canShow()) { |
|
143 | + Log::addMediaLog('Image Builder error: >' . I18N::translate('Missing or private media object.')); |
|
144 | + $this->renderError(); |
|
145 | + } |
|
146 | 146 | |
147 | - $serverFilename = $this->media->getServerFilename(); |
|
147 | + $serverFilename = $this->media->getServerFilename(); |
|
148 | 148 | |
149 | - if (!file_exists($serverFilename)) { |
|
150 | - Log::addMediaLog('Image Builder error: >'. I18N::translate('The media object does not exist.').'< for path >'.$serverFilename.'<'); |
|
151 | - $this->renderError(); |
|
152 | - } |
|
149 | + if (!file_exists($serverFilename)) { |
|
150 | + Log::addMediaLog('Image Builder error: >'. I18N::translate('The media object does not exist.').'< for path >'.$serverFilename.'<'); |
|
151 | + $this->renderError(); |
|
152 | + } |
|
153 | 153 | |
154 | - $mimetype = $this->media->mimeType(); |
|
155 | - $imgsize = $this->media->getImageAttributes(); |
|
156 | - $filetime = $this->media->getFiletime(); |
|
157 | - $filetimeHeader = gmdate('D, d M Y H:i:s', $filetime) . ' GMT'; |
|
158 | - $expireHeader = gmdate('D, d M Y H:i:s', WT_TIMESTAMP + $this->getExpireOffset()) . ' GMT'; |
|
154 | + $mimetype = $this->media->mimeType(); |
|
155 | + $imgsize = $this->media->getImageAttributes(); |
|
156 | + $filetime = $this->media->getFiletime(); |
|
157 | + $filetimeHeader = gmdate('D, d M Y H:i:s', $filetime) . ' GMT'; |
|
158 | + $expireHeader = gmdate('D, d M Y H:i:s', WT_TIMESTAMP + $this->getExpireOffset()) . ' GMT'; |
|
159 | 159 | |
160 | - $type = Functions::isImageTypeSupported($imgsize['ext']); |
|
161 | - $usewatermark = false; |
|
162 | - // if this image supports watermarks and the watermark module is intalled... |
|
163 | - if ($type) { |
|
164 | - $usewatermark = $this->isShowWatermark(); |
|
165 | - } |
|
160 | + $type = Functions::isImageTypeSupported($imgsize['ext']); |
|
161 | + $usewatermark = false; |
|
162 | + // if this image supports watermarks and the watermark module is intalled... |
|
163 | + if ($type) { |
|
164 | + $usewatermark = $this->isShowWatermark(); |
|
165 | + } |
|
166 | 166 | |
167 | - // determine whether we have enough memory to watermark this image |
|
168 | - if ($usewatermark) { |
|
169 | - if (!FunctionsMedia::hasMemoryForImage($serverFilename)) { |
|
170 | - // not enough memory to watermark this file |
|
171 | - $usewatermark = false; |
|
172 | - } |
|
173 | - } |
|
167 | + // determine whether we have enough memory to watermark this image |
|
168 | + if ($usewatermark) { |
|
169 | + if (!FunctionsMedia::hasMemoryForImage($serverFilename)) { |
|
170 | + // not enough memory to watermark this file |
|
171 | + $usewatermark = false; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - $etag = $this->media->getEtag(); |
|
175 | + $etag = $this->media->getEtag(); |
|
176 | 176 | |
177 | - // parse IF_MODIFIED_SINCE header from client |
|
178 | - $if_modified_since = 'x'; |
|
179 | - if (!empty(Filter::server('HTTP_IF_MODIFIED_SINCE'))) { |
|
180 | - $if_modified_since = preg_replace('/;.*$/', '', Filter::server('HTTP_IF_MODIFIED_SINCE')); |
|
181 | - } |
|
177 | + // parse IF_MODIFIED_SINCE header from client |
|
178 | + $if_modified_since = 'x'; |
|
179 | + if (!empty(Filter::server('HTTP_IF_MODIFIED_SINCE'))) { |
|
180 | + $if_modified_since = preg_replace('/;.*$/', '', Filter::server('HTTP_IF_MODIFIED_SINCE')); |
|
181 | + } |
|
182 | 182 | |
183 | - // parse IF_NONE_MATCH header from client |
|
184 | - $if_none_match = 'x'; |
|
185 | - if (!empty(Filter::server('HTTP_IF_NONE_MATCH'))) { |
|
186 | - $if_none_match = str_replace('"', '', Filter::server('HTTP_IF_NONE_MATCH')); |
|
187 | - } |
|
183 | + // parse IF_NONE_MATCH header from client |
|
184 | + $if_none_match = 'x'; |
|
185 | + if (!empty(Filter::server('HTTP_IF_NONE_MATCH'))) { |
|
186 | + $if_none_match = str_replace('"', '', Filter::server('HTTP_IF_NONE_MATCH')); |
|
187 | + } |
|
188 | 188 | |
189 | - // add caching headers. allow browser to cache file, but not proxy |
|
190 | - header('Last-Modified: ' . $filetimeHeader); |
|
191 | - header('ETag: "' . $etag . '"'); |
|
192 | - header('Expires: ' . $expireHeader); |
|
193 | - header('Cache-Control: max-age=' . $this->getExpireOffset() . ', s-maxage=0, proxy-revalidate'); |
|
189 | + // add caching headers. allow browser to cache file, but not proxy |
|
190 | + header('Last-Modified: ' . $filetimeHeader); |
|
191 | + header('ETag: "' . $etag . '"'); |
|
192 | + header('Expires: ' . $expireHeader); |
|
193 | + header('Cache-Control: max-age=' . $this->getExpireOffset() . ', s-maxage=0, proxy-revalidate'); |
|
194 | 194 | |
195 | - // if this file is already in the user’s cache, don’t resend it |
|
196 | - // first check if the if_modified_since param matches |
|
197 | - if ($if_modified_since === $filetimeHeader) { |
|
198 | - // then check if the etag matches |
|
199 | - if ($if_none_match === $etag) { |
|
200 | - http_response_code(304); |
|
195 | + // if this file is already in the user’s cache, don’t resend it |
|
196 | + // first check if the if_modified_since param matches |
|
197 | + if ($if_modified_since === $filetimeHeader) { |
|
198 | + // then check if the etag matches |
|
199 | + if ($if_none_match === $etag) { |
|
200 | + http_response_code(304); |
|
201 | 201 | |
202 | - return; |
|
203 | - } |
|
204 | - } |
|
202 | + return; |
|
203 | + } |
|
204 | + } |
|
205 | 205 | |
206 | - // send headers for the image |
|
207 | - header('Content-Type: ' . $mimetype); |
|
208 | - header('Content-Disposition: filename="' . addslashes(basename($this->media->getFilename())) . '"'); |
|
206 | + // send headers for the image |
|
207 | + header('Content-Type: ' . $mimetype); |
|
208 | + header('Content-Disposition: filename="' . addslashes(basename($this->media->getFilename())) . '"'); |
|
209 | 209 | |
210 | - if ($usewatermark) { |
|
211 | - // generate the watermarked image |
|
212 | - $imCreateFunc = 'imagecreatefrom' . $type; |
|
213 | - $imSendFunc = 'image' . $type; |
|
210 | + if ($usewatermark) { |
|
211 | + // generate the watermarked image |
|
212 | + $imCreateFunc = 'imagecreatefrom' . $type; |
|
213 | + $imSendFunc = 'image' . $type; |
|
214 | 214 | |
215 | - if (function_exists($imCreateFunc) && function_exists($imSendFunc)) { |
|
216 | - $im = $imCreateFunc($serverFilename); |
|
217 | - $im = $this->applyWatermark($im); |
|
215 | + if (function_exists($imCreateFunc) && function_exists($imSendFunc)) { |
|
216 | + $im = $imCreateFunc($serverFilename); |
|
217 | + $im = $this->applyWatermark($im); |
|
218 | 218 | |
219 | - // send the image |
|
220 | - $imSendFunc($im); |
|
221 | - imagedestroy($im); |
|
219 | + // send the image |
|
220 | + $imSendFunc($im); |
|
221 | + imagedestroy($im); |
|
222 | 222 | |
223 | - return; |
|
224 | - } else { |
|
225 | - // this image is defective. log it |
|
226 | - Log::addMediaLog('Image Builder error: >' . I18N::translate('This media file is broken and cannot be watermarked.') . '< in file >' . $serverFilename . '< memory used: ' . memory_get_usage()); |
|
227 | - } |
|
228 | - } |
|
223 | + return; |
|
224 | + } else { |
|
225 | + // this image is defective. log it |
|
226 | + Log::addMediaLog('Image Builder error: >' . I18N::translate('This media file is broken and cannot be watermarked.') . '< in file >' . $serverFilename . '< memory used: ' . memory_get_usage()); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | - // determine filesize of image (could be original or watermarked version) |
|
231 | - $filesize = filesize($serverFilename); |
|
230 | + // determine filesize of image (could be original or watermarked version) |
|
231 | + $filesize = filesize($serverFilename); |
|
232 | 232 | |
233 | - // set content-length header, send file |
|
234 | - header('Content-Length: ' . $filesize); |
|
233 | + // set content-length header, send file |
|
234 | + header('Content-Length: ' . $filesize); |
|
235 | 235 | |
236 | - // Some servers disable fpassthru() and readfile() |
|
237 | - if (function_exists('readfile')) { |
|
238 | - readfile($serverFilename); |
|
239 | - } else { |
|
240 | - $fp = fopen($serverFilename, 'rb'); |
|
241 | - if (function_exists('fpassthru')) { |
|
242 | - fpassthru($fp); |
|
243 | - } else { |
|
244 | - while (!feof($fp)) { |
|
245 | - echo fread($fp, 65536); |
|
246 | - } |
|
247 | - } |
|
248 | - fclose($fp); |
|
249 | - } |
|
236 | + // Some servers disable fpassthru() and readfile() |
|
237 | + if (function_exists('readfile')) { |
|
238 | + readfile($serverFilename); |
|
239 | + } else { |
|
240 | + $fp = fopen($serverFilename, 'rb'); |
|
241 | + if (function_exists('fpassthru')) { |
|
242 | + fpassthru($fp); |
|
243 | + } else { |
|
244 | + while (!feof($fp)) { |
|
245 | + echo fread($fp, 65536); |
|
246 | + } |
|
247 | + } |
|
248 | + fclose($fp); |
|
249 | + } |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | 253 | * Render an error as an image. |
254 | 254 | */ |
255 | 255 | protected function renderError() { |
256 | - $error = I18N::translate('The media file was not found in this family tree.'); |
|
256 | + $error = I18N::translate('The media file was not found in this family tree.'); |
|
257 | 257 | |
258 | - $width = (mb_strlen($error) * 6.5 + 50) * 1.15; |
|
259 | - $height = 60; |
|
260 | - $im = imagecreatetruecolor($width, $height); /* Create a black image */ |
|
261 | - $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ |
|
262 | - imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ |
|
258 | + $width = (mb_strlen($error) * 6.5 + 50) * 1.15; |
|
259 | + $height = 60; |
|
260 | + $im = imagecreatetruecolor($width, $height); /* Create a black image */ |
|
261 | + $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ |
|
262 | + imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ |
|
263 | 263 | |
264 | - $this->embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left'); |
|
264 | + $this->embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left'); |
|
265 | 265 | |
266 | - http_response_code(404); |
|
267 | - header('Content-Type: image/png'); |
|
268 | - imagepng($im); |
|
269 | - imagedestroy($im); |
|
266 | + http_response_code(404); |
|
267 | + header('Content-Type: image/png'); |
|
268 | + imagepng($im); |
|
269 | + imagedestroy($im); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -278,25 +278,25 @@ discard block |
||
278 | 278 | */ |
279 | 279 | protected function applyWatermark($im) { |
280 | 280 | |
281 | - // text to watermark with |
|
282 | - if(method_exists($this->media, 'getWatermarkText')) { |
|
283 | - $word1_text = $this->media->getWatermarkText(); |
|
284 | - } |
|
285 | - else { |
|
286 | - $word1_text = $this->media->getTitle(); |
|
287 | - } |
|
281 | + // text to watermark with |
|
282 | + if(method_exists($this->media, 'getWatermarkText')) { |
|
283 | + $word1_text = $this->media->getWatermarkText(); |
|
284 | + } |
|
285 | + else { |
|
286 | + $word1_text = $this->media->getTitle(); |
|
287 | + } |
|
288 | 288 | |
289 | - $this->embedText( |
|
290 | - $im, |
|
291 | - $word1_text, |
|
292 | - $this->font_max_size, |
|
293 | - $this->font_color, |
|
294 | - WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, |
|
295 | - 'top', |
|
296 | - 'left' |
|
297 | - ); |
|
289 | + $this->embedText( |
|
290 | + $im, |
|
291 | + $word1_text, |
|
292 | + $this->font_max_size, |
|
293 | + $this->font_color, |
|
294 | + WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, |
|
295 | + 'top', |
|
296 | + 'left' |
|
297 | + ); |
|
298 | 298 | |
299 | - return ($im); |
|
299 | + return ($im); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -313,94 +313,94 @@ discard block |
||
313 | 313 | */ |
314 | 314 | protected function embedText($im, $text, $maxsize, $color, $font, $vpos, $hpos) { |
315 | 315 | |
316 | - // there are two ways to embed text with PHP |
|
317 | - // (preferred) using GD and FreeType you can embed text using any True Type font |
|
318 | - // (fall back) if that is not available, you can insert basic monospaced text |
|
316 | + // there are two ways to embed text with PHP |
|
317 | + // (preferred) using GD and FreeType you can embed text using any True Type font |
|
318 | + // (fall back) if that is not available, you can insert basic monospaced text |
|
319 | 319 | |
320 | - $col = $this->hexrgb($color); |
|
321 | - $textcolor = imagecolorallocate($im, $col['red'], $col['green'], $col['blue']); |
|
320 | + $col = $this->hexrgb($color); |
|
321 | + $textcolor = imagecolorallocate($im, $col['red'], $col['green'], $col['blue']); |
|
322 | 322 | |
323 | - // make adjustments to settings that imagestring and imagestringup can’t handle |
|
324 | - if (!$this->use_ttf) { |
|
325 | - // imagestringup only writes up, can’t use top2bottom |
|
326 | - if ($hpos === 'top2bottom') { |
|
327 | - $hpos = 'bottom2top'; |
|
328 | - } |
|
329 | - } |
|
323 | + // make adjustments to settings that imagestring and imagestringup can’t handle |
|
324 | + if (!$this->use_ttf) { |
|
325 | + // imagestringup only writes up, can’t use top2bottom |
|
326 | + if ($hpos === 'top2bottom') { |
|
327 | + $hpos = 'bottom2top'; |
|
328 | + } |
|
329 | + } |
|
330 | 330 | |
331 | - $text = I18N::reverseText($text); |
|
332 | - $height = imagesy($im); |
|
333 | - $width = imagesx($im); |
|
334 | - $calc_angle = rad2deg(atan($height / $width)); |
|
335 | - $hypoth = $height / sin(deg2rad($calc_angle)); |
|
331 | + $text = I18N::reverseText($text); |
|
332 | + $height = imagesy($im); |
|
333 | + $width = imagesx($im); |
|
334 | + $calc_angle = rad2deg(atan($height / $width)); |
|
335 | + $hypoth = $height / sin(deg2rad($calc_angle)); |
|
336 | 336 | |
337 | - // vertical and horizontal position of the text |
|
338 | - switch ($vpos) { |
|
339 | - default: |
|
340 | - case 'top': |
|
341 | - $taille = $this->textLength($maxsize, $width, $text); |
|
342 | - $pos_y = $height * 0.15 + $taille; |
|
343 | - $pos_x = $width * 0.15; |
|
344 | - $rotation = 0; |
|
345 | - break; |
|
346 | - case 'middle': |
|
347 | - $taille = $this->textLength($maxsize, $width, $text); |
|
348 | - $pos_y = ($height + $taille) / 2; |
|
349 | - $pos_x = $width * 0.15; |
|
350 | - $rotation = 0; |
|
351 | - break; |
|
352 | - case 'bottom': |
|
353 | - $taille = $this->textLength($maxsize, $width, $text); |
|
354 | - $pos_y = ($height * .85 - $taille); |
|
355 | - $pos_x = $width * 0.15; |
|
356 | - $rotation = 0; |
|
357 | - break; |
|
358 | - case 'across': |
|
359 | - switch ($hpos) { |
|
360 | - default: |
|
361 | - case 'left': |
|
362 | - $taille = $this->textLength($maxsize, $hypoth, $text); |
|
363 | - $pos_y = ($height * .85 - $taille); |
|
364 | - $pos_x = $width * 0.15; |
|
365 | - $rotation = $calc_angle; |
|
366 | - break; |
|
367 | - case 'right': |
|
368 | - $taille = $this->textLength($maxsize, $hypoth, $text); |
|
369 | - $pos_y = ($height * .15 - $taille); |
|
370 | - $pos_x = $width * 0.85; |
|
371 | - $rotation = $calc_angle + 180; |
|
372 | - break; |
|
373 | - case 'top2bottom': |
|
374 | - $taille = $this->textLength($maxsize, $height, $text); |
|
375 | - $pos_y = ($height * .15 - $taille); |
|
376 | - $pos_x = ($width * .90 - $taille); |
|
377 | - $rotation = -90; |
|
378 | - break; |
|
379 | - case 'bottom2top': |
|
380 | - $taille = $this->textLength($maxsize, $height, $text); |
|
381 | - $pos_y = $height * 0.85; |
|
382 | - $pos_x = $width * 0.15; |
|
383 | - $rotation = 90; |
|
384 | - break; |
|
385 | - } |
|
386 | - break; |
|
387 | - } |
|
337 | + // vertical and horizontal position of the text |
|
338 | + switch ($vpos) { |
|
339 | + default: |
|
340 | + case 'top': |
|
341 | + $taille = $this->textLength($maxsize, $width, $text); |
|
342 | + $pos_y = $height * 0.15 + $taille; |
|
343 | + $pos_x = $width * 0.15; |
|
344 | + $rotation = 0; |
|
345 | + break; |
|
346 | + case 'middle': |
|
347 | + $taille = $this->textLength($maxsize, $width, $text); |
|
348 | + $pos_y = ($height + $taille) / 2; |
|
349 | + $pos_x = $width * 0.15; |
|
350 | + $rotation = 0; |
|
351 | + break; |
|
352 | + case 'bottom': |
|
353 | + $taille = $this->textLength($maxsize, $width, $text); |
|
354 | + $pos_y = ($height * .85 - $taille); |
|
355 | + $pos_x = $width * 0.15; |
|
356 | + $rotation = 0; |
|
357 | + break; |
|
358 | + case 'across': |
|
359 | + switch ($hpos) { |
|
360 | + default: |
|
361 | + case 'left': |
|
362 | + $taille = $this->textLength($maxsize, $hypoth, $text); |
|
363 | + $pos_y = ($height * .85 - $taille); |
|
364 | + $pos_x = $width * 0.15; |
|
365 | + $rotation = $calc_angle; |
|
366 | + break; |
|
367 | + case 'right': |
|
368 | + $taille = $this->textLength($maxsize, $hypoth, $text); |
|
369 | + $pos_y = ($height * .15 - $taille); |
|
370 | + $pos_x = $width * 0.85; |
|
371 | + $rotation = $calc_angle + 180; |
|
372 | + break; |
|
373 | + case 'top2bottom': |
|
374 | + $taille = $this->textLength($maxsize, $height, $text); |
|
375 | + $pos_y = ($height * .15 - $taille); |
|
376 | + $pos_x = ($width * .90 - $taille); |
|
377 | + $rotation = -90; |
|
378 | + break; |
|
379 | + case 'bottom2top': |
|
380 | + $taille = $this->textLength($maxsize, $height, $text); |
|
381 | + $pos_y = $height * 0.85; |
|
382 | + $pos_x = $width * 0.15; |
|
383 | + $rotation = 90; |
|
384 | + break; |
|
385 | + } |
|
386 | + break; |
|
387 | + } |
|
388 | 388 | |
389 | - // apply the text |
|
390 | - if ($this->use_ttf) { |
|
391 | - // if imagettftext throws errors, catch them with a custom error handler |
|
392 | - set_error_handler(array($this, 'imageTtfTextErrorHandler')); |
|
393 | - imagettftext($im, $taille, $rotation, $pos_x, $pos_y, $textcolor, $font, $text); |
|
394 | - restore_error_handler(); |
|
395 | - } |
|
396 | - // Don’t use an ‘else’ here since imagettftextErrorHandler may have changed the value of $useTTF from true to false |
|
397 | - if (!$this->use_ttf) { |
|
398 | - if ($rotation !== 90) { |
|
399 | - imagestring($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
400 | - } else { |
|
401 | - imagestringup($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
402 | - } |
|
403 | - } |
|
389 | + // apply the text |
|
390 | + if ($this->use_ttf) { |
|
391 | + // if imagettftext throws errors, catch them with a custom error handler |
|
392 | + set_error_handler(array($this, 'imageTtfTextErrorHandler')); |
|
393 | + imagettftext($im, $taille, $rotation, $pos_x, $pos_y, $textcolor, $font, $text); |
|
394 | + restore_error_handler(); |
|
395 | + } |
|
396 | + // Don’t use an ‘else’ here since imagettftextErrorHandler may have changed the value of $useTTF from true to false |
|
397 | + if (!$this->use_ttf) { |
|
398 | + if ($rotation !== 90) { |
|
399 | + imagestring($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
400 | + } else { |
|
401 | + imagestringup($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
402 | + } |
|
403 | + } |
|
404 | 404 | |
405 | 405 | } |
406 | 406 | |
@@ -412,53 +412,53 @@ discard block |
||
412 | 412 | */ |
413 | 413 | protected function hexrgb ($hexstr) |
414 | 414 | { |
415 | - $int = hexdec($hexstr); |
|
415 | + $int = hexdec($hexstr); |
|
416 | 416 | |
417 | - return array('red' => 0xFF & ($int >> 0x10), |
|
418 | - 'green' => 0xFF & ($int >> 0x8), |
|
419 | - 'blue' => 0xFF & $int); |
|
417 | + return array('red' => 0xFF & ($int >> 0x10), |
|
418 | + 'green' => 0xFF & ($int >> 0x8), |
|
419 | + 'blue' => 0xFF & $int); |
|
420 | 420 | } |
421 | 421 | |
422 | - /** |
|
423 | - * Generate an approximate length of text, in pixels. |
|
424 | - * |
|
425 | - * @param int $t |
|
426 | - * @param int $mxl |
|
427 | - * @param string $text |
|
428 | - * |
|
429 | - * @return int |
|
430 | - */ |
|
431 | - function textLength($t, $mxl, $text) { |
|
432 | - $taille_c = $t; |
|
433 | - $len = mb_strlen($text); |
|
434 | - while (($taille_c - 2) * $len > $mxl) { |
|
435 | - $taille_c--; |
|
436 | - if ($taille_c == 2) { |
|
437 | - break; |
|
438 | - } |
|
439 | - } |
|
422 | + /** |
|
423 | + * Generate an approximate length of text, in pixels. |
|
424 | + * |
|
425 | + * @param int $t |
|
426 | + * @param int $mxl |
|
427 | + * @param string $text |
|
428 | + * |
|
429 | + * @return int |
|
430 | + */ |
|
431 | + function textLength($t, $mxl, $text) { |
|
432 | + $taille_c = $t; |
|
433 | + $len = mb_strlen($text); |
|
434 | + while (($taille_c - 2) * $len > $mxl) { |
|
435 | + $taille_c--; |
|
436 | + if ($taille_c == 2) { |
|
437 | + break; |
|
438 | + } |
|
439 | + } |
|
440 | 440 | |
441 | - return $taille_c; |
|
442 | - } |
|
441 | + return $taille_c; |
|
442 | + } |
|
443 | 443 | |
444 | - /** |
|
445 | - * imagettftext is the function that is most likely to throw an error |
|
446 | - * use this custom error handler to catch and log it |
|
447 | - * |
|
448 | - * @param int $errno |
|
449 | - * @param string $errstr |
|
450 | - * |
|
451 | - * @return bool |
|
452 | - */ |
|
453 | - function imageTtfTextErrorHandler($errno, $errstr) { |
|
454 | - // log the error |
|
455 | - Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<'); |
|
444 | + /** |
|
445 | + * imagettftext is the function that is most likely to throw an error |
|
446 | + * use this custom error handler to catch and log it |
|
447 | + * |
|
448 | + * @param int $errno |
|
449 | + * @param string $errstr |
|
450 | + * |
|
451 | + * @return bool |
|
452 | + */ |
|
453 | + function imageTtfTextErrorHandler($errno, $errstr) { |
|
454 | + // log the error |
|
455 | + Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<'); |
|
456 | 456 | |
457 | - // change value of useTTF to false so the fallback watermarking can be used. |
|
458 | - $this->use_ttf = false; |
|
457 | + // change value of useTTF to false so the fallback watermarking can be used. |
|
458 | + $this->use_ttf = false; |
|
459 | 459 | |
460 | - return true; |
|
461 | - } |
|
460 | + return true; |
|
461 | + } |
|
462 | 462 | |
463 | 463 | } |
464 | 464 |