PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / tecnickcom / tcpdf / include / tcpdf_images.php
matomo / app / vendor / tecnickcom / tcpdf / include Last commit date
barcodes 2 years ago sRGB.icc 6 years ago tcpdf_colors.php 7 months ago tcpdf_filters.php 2 years ago tcpdf_font_data.php 2 years ago tcpdf_fonts.php 1 year ago tcpdf_images.php 2 years ago tcpdf_static.php 4 months ago
tcpdf_images.php
358 lines
1 <?php
2
3 namespace {
4 //============================================================+
5 // File name : tcpdf_images.php
6 // Version : 1.0.005
7 // Begin : 2002-08-03
8 // Last Update : 2014-11-15
9 // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
10 // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
11 // -------------------------------------------------------------------
12 // Copyright (C) 2002-2014 Nicola Asuni - Tecnick.com LTD
13 //
14 // This file is part of TCPDF software library.
15 //
16 // TCPDF is free software: you can redistribute it and/or modify it
17 // under the terms of the GNU Lesser General Public License as
18 // published by the Free Software Foundation, either version 3 of the
19 // License, or (at your option) any later version.
20 //
21 // TCPDF is distributed in the hope that it will be useful, but
22 // WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 // See the GNU Lesser General Public License for more details.
25 //
26 // You should have received a copy of the License
27 // along with TCPDF. If not, see
28 // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
29 //
30 // See LICENSE.TXT file for more information.
31 // -------------------------------------------------------------------
32 //
33 // Description :
34 // Static image methods used by the TCPDF class.
35 //
36 //============================================================+
37 /**
38 * @file
39 * This is a PHP class that contains static image methods for the TCPDF class.<br>
40 * @package com.tecnick.tcpdf
41 * @author Nicola Asuni
42 * @version 1.0.005
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 * @var string[]
60 */
61 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');
62 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 /**
64 * Return the image type given the file name or array returned by getimagesize() function.
65 * @param string $imgfile image file name
66 * @param array $iminfo 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 {
73 $type = '';
74 if (isset($iminfo['mime']) and !empty($iminfo['mime'])) {
75 $mime = \explode('/', $iminfo['mime']);
76 if (\count($mime) > 1 and $mime[0] == 'image' and !empty($mime[1])) {
77 $type = \strtolower(\trim($mime[1]));
78 }
79 }
80 if (empty($type)) {
81 $type = \strtolower(\trim(\pathinfo(\parse_url($imgfile, \PHP_URL_PATH), \PATHINFO_EXTENSION)));
82 }
83 if ($type == 'jpg') {
84 $type = 'jpeg';
85 }
86 return $type;
87 }
88 /**
89 * Set the transparency for the given GD image.
90 * @param resource $new_image GD image object
91 * @param resource $image GD image object.
92 * @return resource GD image object $new_image
93 * @since 4.9.016 (2010-04-20)
94 * @public static
95 */
96 public static function setGDImageTransparency($new_image, $image)
97 {
98 // default transparency color (white)
99 $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
100 // transparency index
101 $tid = \imagecolortransparent($image);
102 $palletsize = \imagecolorstotal($image);
103 if ($tid >= 0 and $tid < $palletsize) {
104 // get the colors for the transparency index
105 $tcol = \imagecolorsforindex($image, $tid);
106 }
107 $tid = \imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
108 \imagefill($new_image, 0, 0, $tid);
109 \imagecolortransparent($new_image, $tid);
110 return $new_image;
111 }
112 /**
113 * Convert the loaded image to a PNG and then return a structure for the PDF creator.
114 * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
115 * @param resource $image Image object.
116 * @param string $tempfile Temporary file name.
117 * return image PNG image object.
118 * @since 4.9.016 (2010-04-20)
119 * @public static
120 */
121 public static function _toPNG($image, $tempfile)
122 {
123 // turn off interlaced mode
124 \imageinterlace($image, 0);
125 // create temporary PNG image
126 \imagepng($image, $tempfile);
127 // remove image from memory
128 \imagedestroy($image);
129 // get PNG image data
130 $retvars = self::_parsepng($tempfile);
131 // tidy up by removing temporary image
132 \unlink($tempfile);
133 return $retvars;
134 }
135 /**
136 * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
137 * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
138 * @param resource $image Image object.
139 * @param int $quality JPEG quality.
140 * @param string $tempfile Temporary file name.
141 * return array|false image JPEG image object.
142 * @public static
143 */
144 public static function _toJPEG($image, $quality, $tempfile)
145 {
146 \imagejpeg($image, $tempfile, $quality);
147 \imagedestroy($image);
148 $retvars = self::_parsejpeg($tempfile);
149 // tidy up by removing temporary image
150 \unlink($tempfile);
151 return $retvars;
152 }
153 /**
154 * Extract info from a JPEG file without using the GD library.
155 * @param string $file image file to parse
156 * @return array|false structure containing the image data
157 * @public static
158 */
159 public static function _parsejpeg($file)
160 {
161 // check if is a local file
162 if (!@\TCPDF_STATIC::file_exists($file)) {
163 return \false;
164 }
165 $a = \getimagesize($file);
166 if (empty($a)) {
167 //Missing or incorrect image file
168 return \false;
169 }
170 if ($a[2] != 2) {
171 // Not a JPEG file
172 return \false;
173 }
174 // bits per pixel
175 $bpc = isset($a['bits']) ? \intval($a['bits']) : 8;
176 // number of image channels
177 if (!isset($a['channels'])) {
178 $channels = 3;
179 } else {
180 $channels = \intval($a['channels']);
181 }
182 // default colour space
183 switch ($channels) {
184 case 1:
185 $colspace = 'DeviceGray';
186 break;
187 case 3:
188 $colspace = 'DeviceRGB';
189 break;
190 case 4:
191 $colspace = 'DeviceCMYK';
192 break;
193 default:
194 $channels = 3;
195 $colspace = 'DeviceRGB';
196 break;
197 }
198 // get file content
199 $data = \file_get_contents($file);
200 // check for embedded ICC profile
201 $icc = array();
202 $offset = 0;
203 while (($pos = \strpos($data, "ICC_PROFILE\x00", $offset)) !== \false) {
204 // get ICC sequence length
205 $length = \TCPDF_STATIC::_getUSHORT($data, $pos - 2) - 16;
206 // marker sequence number
207 $msn = \max(1, \ord($data[$pos + 12]));
208 // number of markers (total of APP2 used)
209 $nom = \max(1, \ord($data[$pos + 13]));
210 // get sequence segment
211 $icc[$msn - 1] = \substr($data, $pos + 14, $length);
212 // move forward to next sequence
213 $offset = $pos + 14 + $length;
214 }
215 // order and compact ICC segments
216 if (\count($icc) > 0) {
217 \ksort($icc);
218 $icc = \implode('', $icc);
219 if (\ord($icc[36]) != 0x61 or \ord($icc[37]) != 0x63 or \ord($icc[38]) != 0x73 or \ord($icc[39]) != 0x70) {
220 // invalid ICC profile
221 $icc = \false;
222 }
223 } else {
224 $icc = \false;
225 }
226 return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
227 }
228 /**
229 * Extract info from a PNG file without using the GD library.
230 * @param string $file image file to parse
231 * @return array|false structure containing the image data
232 * @public static
233 */
234 public static function _parsepng($file)
235 {
236 $f = @\fopen($file, 'rb');
237 if ($f === \false) {
238 // Can't open image file
239 return \false;
240 }
241 //Check signature
242 if (\fread($f, 8) != \chr(137) . 'PNG' . \chr(13) . \chr(10) . \chr(26) . \chr(10)) {
243 // Not a PNG file
244 return \false;
245 }
246 //Read header chunk
247 \fread($f, 4);
248 if (\fread($f, 4) != 'IHDR') {
249 //Incorrect PNG file
250 return \false;
251 }
252 $w = \TCPDF_STATIC::_freadint($f);
253 $h = \TCPDF_STATIC::_freadint($f);
254 $bpc = \ord(\fread($f, 1));
255 $ct = \ord(\fread($f, 1));
256 if ($ct == 0) {
257 $colspace = 'DeviceGray';
258 } elseif ($ct == 2) {
259 $colspace = 'DeviceRGB';
260 } elseif ($ct == 3) {
261 $colspace = 'Indexed';
262 } else {
263 // alpha channel
264 \fclose($f);
265 return 'pngalpha';
266 }
267 if (\ord(\fread($f, 1)) != 0) {
268 // Unknown compression method
269 \fclose($f);
270 return \false;
271 }
272 if (\ord(\fread($f, 1)) != 0) {
273 // Unknown filter method
274 \fclose($f);
275 return \false;
276 }
277 if (\ord(\fread($f, 1)) != 0) {
278 // Interlacing not supported
279 \fclose($f);
280 return \false;
281 }
282 \fread($f, 4);
283 $channels = $ct == 2 ? 3 : 1;
284 $parms = '/DecodeParms << /Predictor 15 /Colors ' . $channels . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w . ' >>';
285 //Scan chunks looking for palette, transparency and image data
286 $pal = '';
287 $trns = '';
288 $data = '';
289 $icc = \false;
290 $n = \TCPDF_STATIC::_freadint($f);
291 do {
292 $type = \fread($f, 4);
293 if ($type == 'PLTE') {
294 // read palette
295 $pal = \TCPDF_STATIC::rfread($f, $n);
296 \fread($f, 4);
297 } elseif ($type == 'tRNS') {
298 // read transparency info
299 $t = \TCPDF_STATIC::rfread($f, $n);
300 if ($ct == 0) {
301 // DeviceGray
302 $trns = array(\ord($t[1]));
303 } elseif ($ct == 2) {
304 // DeviceRGB
305 $trns = array(\ord($t[1]), \ord($t[3]), \ord($t[5]));
306 } else {
307 // Indexed
308 if ($n > 0) {
309 $trns = array();
310 for ($i = 0; $i < $n; ++$i) {
311 $trns[] = \ord($t[$i]);
312 }
313 }
314 }
315 \fread($f, 4);
316 } elseif ($type == 'IDAT') {
317 // read image data block
318 $data .= \TCPDF_STATIC::rfread($f, $n);
319 \fread($f, 4);
320 } elseif ($type == 'iCCP') {
321 // skip profile name
322 $len = 0;
323 while (\ord(\fread($f, 1)) != 0 and $len < 80) {
324 ++$len;
325 }
326 // get compression method
327 if (\ord(\fread($f, 1)) != 0) {
328 // Unknown filter method
329 \fclose($f);
330 return \false;
331 }
332 // read ICC Color Profile
333 $icc = \TCPDF_STATIC::rfread($f, $n - $len - 2);
334 // decompress profile
335 $icc = \gzuncompress($icc);
336 \fread($f, 4);
337 } elseif ($type == 'IEND') {
338 break;
339 } else {
340 \TCPDF_STATIC::rfread($f, $n + 4);
341 }
342 $n = \TCPDF_STATIC::_freadint($f);
343 } while ($n);
344 if ($colspace == 'Indexed' and empty($pal)) {
345 // Missing palette
346 \fclose($f);
347 return \false;
348 }
349 \fclose($f);
350 return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
351 }
352 }
353 // END OF TCPDF_IMAGES CLASS
354 //============================================================+
355 // END OF FILE
356 //============================================================+
357 }
358