59 public static $svginheritprop = array(
'clip-rule',
'color',
'color-interpolation',
'color-interpolation-filters',
'color-profile',
'color-rendering',
'cursor',
'direction',
'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');
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]));
80 $fileinfo = pathinfo($imgfile);
82 $type = strtolower(trim($fileinfo[
'extension']));
101 $tid = imagecolortransparent($image);
103 $tcol = array(
'red' => 255,
'green' => 255,
'blue' => 255);
106 $tcol = imagecolorsforindex($image, $tid);
108 $tid = imagecolorallocate($new_image, $tcol[
'red'], $tcol[
'green'], $tcol[
'blue']);
109 imagefill($new_image, 0, 0, $tid);
110 imagecolortransparent($new_image, $tid);
126 imageinterlace($image, 0);
128 imagepng($image, $tempname);
130 imagedestroy($image);
146 public static function _toJPEG($image, $quality) {
148 imagejpeg($image, $tempname, $quality);
149 imagedestroy($image);
163 $a = getimagesize(
$file);
173 $bpc = isset($a[
'bits']) ? intval($a[
'bits']) : 8;
175 if (!isset($a[
'channels'])) {
178 $channels = intval($a[
'channels']);
183 $colspace =
'DeviceGray';
187 $colspace =
'DeviceRGB';
191 $colspace =
'DeviceCMYK';
196 $colspace =
'DeviceRGB';
201 $data = file_get_contents(
$file);
205 while (($pos = strpos($data,
"ICC_PROFILE\0", $offset)) !==
false) {
209 $msn = max(1, ord($data[($pos + 12)]));
211 $nom = max(1, ord($data[($pos + 13)]));
213 $icc[($msn - 1)] = substr($data, ($pos + 14), $length);
215 $offset = ($pos + 14 + $length);
218 if (count($icc) > 0) {
220 $icc = implode(
'', $icc);
221 if ((ord($icc{36}) != 0x61) OR (ord($icc{37}) != 0x63) OR (ord($icc{38}) != 0x73) OR (ord($icc{39}) != 0x70)) {
228 return array(
'w' => $a[0],
'h' => $a[1],
'ch' => $channels,
'icc' => $icc,
'cs' => $colspace,
'bpc' => $bpc,
'f' =>
'DCTDecode',
'data' => $data);
238 $f = fopen(
$file,
'rb');
244 if (fread($f, 8) != chr(137).
'PNG'.chr(13).chr(10).chr(26).chr(10)) {
250 if (fread($f, 4) !=
'IHDR') {
256 $bpc = ord(fread($f, 1));
262 $ct = ord(fread($f, 1));
264 $colspace =
'DeviceGray';
265 } elseif ($ct == 2) {
266 $colspace =
'DeviceRGB';
267 } elseif ($ct == 3) {
268 $colspace =
'Indexed';
274 if (ord(fread($f, 1)) != 0) {
279 if (ord(fread($f, 1)) != 0) {
284 if (ord(fread($f, 1)) != 0) {
290 $channels = ($ct == 2 ? 3 : 1);
291 $parms =
'/DecodeParms << /Predictor 15 /Colors '.$channels.
' /BitsPerComponent '.$bpc.
' /Columns '.$w.
' >>';
299 $type = fread($f, 4);
300 if ($type ==
'PLTE') {
304 } elseif ($type ==
'tRNS') {
308 $trns = array(ord(
$t{1}));
309 } elseif ($ct == 2) {
310 $trns = array(ord(
$t{1}), ord(
$t{3}), ord(
$t{5}));
312 $pos = strpos(
$t, chr(0));
313 if ($pos !==
false) {
318 } elseif ($type ==
'IDAT') {
322 } elseif ($type ==
'iCCP') {
325 while ((ord(fread($f, 1)) > 0) AND ($len < 80)) {
331 if (ord(fread($f, 1)) != 0) {
339 $icc = gzuncompress($icc);
341 } elseif ($type ==
'IEND') {
347 if (($colspace ==
'Indexed') AND (empty($pal))) {
353 return array(
'w' => $w,
'h' => $h,
'ch' => $channels,
'icc' => $icc,
'cs' => $colspace,
'bpc' => $bpc,
'f' =>
'FlateDecode',
'parms' => $parms,
'pal' => $pal,
'trns' => $trns,
'data' => $data);