PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.7
GiveWP – Donation Plugin and Fundraising Platform v2.1.7
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / libraries / tcpdf / include / tcpdf_images.php
give / includes / libraries / tcpdf / include Last commit date
barcodes 8 years ago sRGB.icc 8 years ago tcpdf_colors.php 8 years ago tcpdf_filters.php 8 years ago tcpdf_font_data.php 8 years ago tcpdf_fonts.php 8 years ago tcpdf_images.php 8 years ago tcpdf_static.php 8 years ago
tcpdf_images.php
365 lines
1 <?php
2 //============================================================+
3 // File name : tcpdf_images.php
4 // Version : 1.0.005
5 // Begin : 2002-08-03
6 // Last Update : 2014-11-15
7 // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
8 // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
9 // -------------------------------------------------------------------
10 // Copyright (C) 2002-2014 Nicola Asuni - Tecnick.com LTD
11 //
12 // This file is part of TCPDF software library.
13 //
14 // TCPDF is free software: you can redistribute it and/or modify it
15 // under the terms of the GNU Lesser General Public License as
16 // published by the Free Software Foundation, either version 3 of the
17 // License, or (at your option) any later version.
18 //
19 // TCPDF is distributed in the hope that it will be useful, but
20 // WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 // See the GNU Lesser General Public License for more details.
23 //
24 // You should have received a copy of the License
25 // along with TCPDF. If not, see
26 // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
27 //
28 // See LICENSE.TXT file for more information.
29 // -------------------------------------------------------------------
30 //
31 // Description :
32 // Static image methods used by the TCPDF class.
33 //
34 //============================================================+
35
36 /**
37 * @file
38 * This is a PHP class that contains static image methods for the TCPDF class.<br>
39 * @package com.tecnick.tcpdf
40 * @author Nicola Asuni
41 * @version 1.0.005
42 */
43
44 /**
45 * @class TCPDF_IMAGES
46 * Static image methods used by the TCPDF class.
47 * @package com.tecnick.tcpdf
48 * @brief PHP class for generating PDF documents without requiring external extensions.
49 * @version 1.0.005
50 * @author Nicola Asuni - info@tecnick.com
51 */
52 class TCPDF_IMAGES {
53
54 /**
55 * Array of hinheritable SVG properties.
56 * @since 5.0.000 (2010-05-02)
57 * @public static
58 */
59 public static $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'display', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode');
60
61 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62
63 /**
64 * Return the image type given the file name or array returned by getimagesize() function.
65 * @param $imgfile (string) image file name
66 * @param $iminfo (array) array of image information returned by getimagesize() function.
67 * @return string image type
68 * @since 4.8.017 (2009-11-27)
69 * @public static
70 */
71 public static function getImageFileType($imgfile, $iminfo=array()) {
72 $type = '';
73 if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
74 $mime = explode('/', $iminfo['mime']);
75 if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
76 $type = strtolower(trim($mime[1]));
77 }
78 }
79 if (empty($type)) {
80 $fileinfo = pathinfo($imgfile);
81 if (isset($fileinfo['extension']) AND (!TCPDF_STATIC::empty_string($fileinfo['extension']))) {
82 $type = strtolower(trim($fileinfo['extension']));
83 }
84 }
85 if ($type == 'jpg') {
86 $type = 'jpeg';
87 }
88 return $type;
89 }
90
91 /**
92 * Set the transparency for the given GD image.
93 * @param $new_image (image) GD image object
94 * @param $image (image) GD image object.
95 * return GD image object.
96 * @since 4.9.016 (2010-04-20)
97 * @public static
98 */
99 public static function setGDImageTransparency($new_image, $image) {
100 // default transparency color (white)
101 $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
102 // transparency index
103 $tid = imagecolortransparent($image);
104 $palletsize = imagecolorstotal($image);
105 if (($tid >= 0) AND ($tid < $palletsize)) {
106 // get the colors for the transparency index
107 $tcol = imagecolorsforindex($image, $tid);
108 }
109 $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
110 imagefill($new_image, 0, 0, $tid);
111 imagecolortransparent($new_image, $tid);
112 return $new_image;
113 }
114
115 /**
116 * Convert the loaded image to a PNG and then return a structure for the PDF creator.
117 * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
118 * @param $image (image) Image object.
119 * @param $tempfile (string) Temporary file name.
120 * return image PNG image object.
121 * @since 4.9.016 (2010-04-20)
122 * @public static
123 */
124 public static function _toPNG($image, $tempfile) {
125 // turn off interlaced mode
126 imageinterlace($image, 0);
127 // create temporary PNG image
128 imagepng($image, $tempfile);
129 // remove image from memory
130 imagedestroy($image);
131 // get PNG image data
132 $retvars = self::_parsepng($tempfile);
133 // tidy up by removing temporary image
134 unlink($tempfile);
135 return $retvars;
136 }
137
138 /**
139 * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
140 * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
141 * @param $image (image) Image object.
142 * @param $quality (int) JPEG quality.
143 * @param $tempfile (string) Temporary file name.
144 * return image JPEG image object.
145 * @public static
146 */
147 public static function _toJPEG($image, $quality, $tempfile) {
148 imagejpeg($image, $tempfile, $quality);
149 imagedestroy($image);
150 $retvars = self::_parsejpeg($tempfile);
151 // tidy up by removing temporary image
152 unlink($tempfile);
153 return $retvars;
154 }
155
156 /**
157 * Extract info from a JPEG file without using the GD library.
158 * @param $file (string) image file to parse
159 * @return array structure containing the image data
160 * @public static
161 */
162 public static function _parsejpeg($file) {
163 // check if is a local file
164 if (!@file_exists($file)) {
165 // try to encode spaces on filename
166 $tfile = str_replace(' ', '%20', $file);
167 if (@file_exists($tfile)) {
168 $file = $tfile;
169 }
170 }
171 $a = getimagesize($file);
172 if (empty($a)) {
173 //Missing or incorrect image file
174 return false;
175 }
176 if ($a[2] != 2) {
177 // Not a JPEG file
178 return false;
179 }
180 // bits per pixel
181 $bpc = isset($a['bits']) ? intval($a['bits']) : 8;
182 // number of image channels
183 if (!isset($a['channels'])) {
184 $channels = 3;
185 } else {
186 $channels = intval($a['channels']);
187 }
188 // default colour space
189 switch ($channels) {
190 case 1: {
191 $colspace = 'DeviceGray';
192 break;
193 }
194 case 3: {
195 $colspace = 'DeviceRGB';
196 break;
197 }
198 case 4: {
199 $colspace = 'DeviceCMYK';
200 break;
201 }
202 default: {
203 $channels = 3;
204 $colspace = 'DeviceRGB';
205 break;
206 }
207 }
208 // get file content
209 $data = file_get_contents($file);
210 // check for embedded ICC profile
211 $icc = array();
212 $offset = 0;
213 while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) {
214 // get ICC sequence length
215 $length = (TCPDF_STATIC::_getUSHORT($data, ($pos - 2)) - 16);
216 // marker sequence number
217 $msn = max(1, ord($data[($pos + 12)]));
218 // number of markers (total of APP2 used)
219 $nom = max(1, ord($data[($pos + 13)]));
220 // get sequence segment
221 $icc[($msn - 1)] = substr($data, ($pos + 14), $length);
222 // move forward to next sequence
223 $offset = ($pos + 14 + $length);
224 }
225 // order and compact ICC segments
226 if (count($icc) > 0) {
227 ksort($icc);
228 $icc = implode('', $icc);
229 if ((ord($icc[36]) != 0x61) OR (ord($icc[37]) != 0x63) OR (ord($icc[38]) != 0x73) OR (ord($icc[39]) != 0x70)) {
230 // invalid ICC profile
231 $icc = false;
232 }
233 } else {
234 $icc = false;
235 }
236 return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
237 }
238
239 /**
240 * Extract info from a PNG file without using the GD library.
241 * @param $file (string) image file to parse
242 * @return array structure containing the image data
243 * @public static
244 */
245 public static function _parsepng($file) {
246 $f = @fopen($file, 'rb');
247 if ($f === false) {
248 // Can't open image file
249 return false;
250 }
251 //Check signature
252 if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
253 // Not a PNG file
254 return false;
255 }
256 //Read header chunk
257 fread($f, 4);
258 if (fread($f, 4) != 'IHDR') {
259 //Incorrect PNG file
260 return false;
261 }
262 $w = TCPDF_STATIC::_freadint($f);
263 $h = TCPDF_STATIC::_freadint($f);
264 $bpc = ord(fread($f, 1));
265 $ct = ord(fread($f, 1));
266 if ($ct == 0) {
267 $colspace = 'DeviceGray';
268 } elseif ($ct == 2) {
269 $colspace = 'DeviceRGB';
270 } elseif ($ct == 3) {
271 $colspace = 'Indexed';
272 } else {
273 // alpha channel
274 fclose($f);
275 return 'pngalpha';
276 }
277 if (ord(fread($f, 1)) != 0) {
278 // Unknown compression method
279 fclose($f);
280 return false;
281 }
282 if (ord(fread($f, 1)) != 0) {
283 // Unknown filter method
284 fclose($f);
285 return false;
286 }
287 if (ord(fread($f, 1)) != 0) {
288 // Interlacing not supported
289 fclose($f);
290 return false;
291 }
292 fread($f, 4);
293 $channels = ($ct == 2 ? 3 : 1);
294 $parms = '/DecodeParms << /Predictor 15 /Colors '.$channels.' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
295 //Scan chunks looking for palette, transparency and image data
296 $pal = '';
297 $trns = '';
298 $data = '';
299 $icc = false;
300 $n = TCPDF_STATIC::_freadint($f);
301 do {
302 $type = fread($f, 4);
303 if ($type == 'PLTE') {
304 // read palette
305 $pal = TCPDF_STATIC::rfread($f, $n);
306 fread($f, 4);
307 } elseif ($type == 'tRNS') {
308 // read transparency info
309 $t = TCPDF_STATIC::rfread($f, $n);
310 if ($ct == 0) { // DeviceGray
311 $trns = array(ord($t[1]));
312 } elseif ($ct == 2) { // DeviceRGB
313 $trns = array(ord($t[1]), ord($t[3]), ord($t[5]));
314 } else { // Indexed
315 if ($n > 0) {
316 $trns = array();
317 for ($i = 0; $i < $n; ++ $i) {
318 $trns[] = ord($t{$i});
319 }
320 }
321 }
322 fread($f, 4);
323 } elseif ($type == 'IDAT') {
324 // read image data block
325 $data .= TCPDF_STATIC::rfread($f, $n);
326 fread($f, 4);
327 } elseif ($type == 'iCCP') {
328 // skip profile name
329 $len = 0;
330 while ((ord(fread($f, 1)) != 0) AND ($len < 80)) {
331 ++$len;
332 }
333 // get compression method
334 if (ord(fread($f, 1)) != 0) {
335 // Unknown filter method
336 fclose($f);
337 return false;
338 }
339 // read ICC Color Profile
340 $icc = TCPDF_STATIC::rfread($f, ($n - $len - 2));
341 // decompress profile
342 $icc = gzuncompress($icc);
343 fread($f, 4);
344 } elseif ($type == 'IEND') {
345 break;
346 } else {
347 TCPDF_STATIC::rfread($f, $n + 4);
348 }
349 $n = TCPDF_STATIC::_freadint($f);
350 } while ($n);
351 if (($colspace == 'Indexed') AND (empty($pal))) {
352 // Missing palette
353 fclose($f);
354 return false;
355 }
356 fclose($f);
357 return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
358 }
359
360 } // END OF TCPDF_IMAGES CLASS
361
362 //============================================================+
363 // END OF FILE
364 //============================================================+
365