Lines Matching +full:font +full:- +full:size +(+path:plugin +path:dw2pdf) -(+path:plugin +path:dw2pdf +path:lang)

112 		$this->mpdf = $mpdf;
113 $this->otl = $otl;
114 $this->cssManager = $cssManager;
115 $this->sizeConverter = $sizeConverter;
116 $this->colorConverter = $colorConverter;
117 $this->colorModeConverter = $colorModeConverter;
118 $this->cache = $cache;
119 $this->languageToFont = $languageToFont;
120 $this->scriptToLanguage = $scriptToLanguage;
121 $this->remoteContentFetcher = $remoteContentFetcher;
123 $this->logger = $logger;
125 $this->guesser = new ImageTypeGuesser();
127 $this->failedImages = [];
137 $this->logger = $logger;
149 $wrapperChecker = new StreamWrapperChecker($this->mpdf);
150 if ($wrapperChecker->hasBlacklistedStreamWrapper($file)) {
151 return $this->imageError($file, $firsttime, 'File contains an invalid stream. Only ' . implode(', ', $wrapperChecker->getWhitelistedStreamWrappers()) . ' streams are allowed.');
153 if ($wrapperChecker->hasBlacklistedStreamWrapper($orig_srcpath)) {
154 return $this->imageError($orig_srcpath, $firsttime, 'File contains an invalid stream. Only ' . implode(', ', $wrapperChecker->getWhitelistedStreamWrappers()) . ' streams are allowed.');
158 // firsttime i.e. whether to add to this->images - use false when calling iteratively
165 if (!isset($this->mpdf->imageVars[$v[1]])) {
166 return $this->imageError($file, $firsttime, 'Unknown image variable');
168 $data = $this->mpdf->imageVars[$v[1]];
188 $orig_srcpath = $this->urldecodeParts($orig_srcpath);
193 if ($orig_srcpath && isset($this->mpdf->images[$orig_srcpath])) {
195 return $this->mpdf->images[$orig_srcpath];
198 if (isset($this->mpdf->images[$file])) {
199 return $this->mpdf->images[$file];
202 if ($orig_srcpath && isset($this->mpdf->formobjects[$orig_srcpath])) {
204 return $this->mpdf->formobjects[$file];
207 if (isset($this->mpdf->formobjects[$file])) {
208 return $this->mpdf->formobjects[$file];
211 if ($firsttime && isset($this->failedImages[$file])) { // Save re-trying image URL's which have already failed
212 return $this->imageError($file, $firsttime, '');
219 if ($orig_srcpath && $this->mpdf->basepathIsLocal && $check = @fopen($orig_srcpath, 'rb')) {
222 $this->logger->debug(sprintf('Fetching (file_get_contents) content of file "%s" with local basepath', $file), ['context' => LogContext::REMOTE_CONTENT]);
224 $type = $this->guesser->guess($data);
229 $this->logger->debug(sprintf('Fetching (file_get_contents) content of file "%s" with non-local basepath', $file), ['context' => LogContext::REMOTE_CONTENT]);
231 $type = $this->guesser->guess($data);
235 $data = $this->remoteContentFetcher->getFileContentsByCurl($file); // needs full url?? even on local (never needed for local)
237 $type = $this->guesser->guess($data);
242 $data = $this->remoteContentFetcher->getFileContentsBySocket($file); // needs full url?? even on local (never needed for local)
244 $type = $this->guesser->guess($data);
250 return $this->imageError($file, $firsttime, 'Could not find image file');
254 $type = $this->guesser->guess($data);
258 return $this->imageError($file, $firsttime, 'WMF or SVG image file not supported in this context');
263 $svg = new Svg($this->mpdf, $this->otl, $this->cssManager, $this, $this->sizeConverter, $this->colorConverter, $this->languageToFont, $this->scriptToLanguage);
264 $family = $this->mpdf->FontFamily;
265 $style = $this->mpdf->FontStyle;
266 $size = $this->mpdf->FontSizePt;
267 $info = $svg->ImageSVG($data);
268 // Restore font
270 $this->mpdf->SetFont($family, $style, $size, false);
273 return $this->imageError($file, $firsttime, 'Error parsing SVG file');
276 $info['i'] = count($this->mpdf->formobjects) + 1;
277 $this->mpdf->formobjects[$file] = $info;
287 return $this->imageError($file, $firsttime, 'Missing GD support for WEBP images.');
290 $tempfile = $this->cache->tempFilename('_tempImgPNG' . md5($file) . random_int(1, 10000) . '.jpg');
291 $checkfile = $this->cache->tempFilename('_tempImgPNG' . md5($file) . random_int(1, 10000) . '.jpg');
295 return $this->imageError($file, $firsttime, 'Error creating temporary file (' . $tempfile . ') when using GD library to parse WEBP image');
310 $hdr = $this->jpgHeaderFromString($data);
312 return $this->imageError($file, $firsttime, 'Error parsing JPG header');
315 $a = $this->jpgDataFromHeader($hdr);
323 $ppUx = $this->twoBytesToInt(substr($data, $j + 8, 2)); // horizontal pixels per meter, usually set to zero
330 if ($a[2] === 'DeviceCMYK' && ($this->mpdf->restrictColorSpace === 2 || ($this->mpdf->PDFA && $this->mpdf->restrictColorSpace !== 3))) {
337 if ($this->mpdf->PDFA && !$this->mpdf->PDFAauto) {
338 $this->mpdf->PDFAXwarnings[] = sprintf('JPG image may not use CMYK color space - %s - (Image converted to RGB. NB This will alter the colour profile of the image.)', $file);
344 $tempfile = $this->cache->tempFilename('_tempImgPNG' . md5($file) . random_int(1, 10000) . '.png');
348 return $this->imageError($file, $firsttime, 'Error creating temporary file (' . $tempfile . ') when using GD library to parse JPG(CMYK) image');
350 $info = $this->getImage($tempfile, false);
352 return $this->imageError($file, $firsttime, 'Error parsing temporary file (' . $tempfile . ') created with GD library to parse JPG(CMYK) image');
358 $info['i'] = count($this->mpdf->images) + 1;
360 $this->mpdf->images[$file] = $info;
365 return $this->imageError($file, $firsttime, 'Error creating GD image file from JPG(CMYK) image');
369 if ($a[2] === 'DeviceRGB' && ($this->mpdf->PDFX || $this->mpdf->restrictColorSpace === 3)) {
370 // Convert to CMYK image stream - nominally returned as type='png'
371 $info = $this->convertImage($data, $a[2], 'DeviceCMYK', $a[0], $a[1], $ppUx, false);
372 if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) {
373 $this->mpdf->PDFAXwarnings[] = sprintf('JPG image may not use RGB color space - %s - (Image converted to CMYK. NB This will alter the colour profile of the image.)', $file);
376 } elseif (($a[2] === 'DeviceRGB' || $a[2] === 'DeviceCMYK') && $this->mpdf->restrictColorSpace === 1) {
377 // Convert to Grayscale image stream - nominally returned as type='png'
378 $info = $this->convertImage($data, $a[2], 'DeviceGray', $a[0], $a[1], $ppUx, false);
390 $length = $this->twoBytesToInt(substr($data, $pos - 2, 2)) - 16;
393 $icc[$sn - 1] = substr($data, $pos + 14, $length);
416 $info['set-dpi'] = $ppUx;
421 return $this->imageError($file, $firsttime, 'Error parsing or converting JPG image');
425 $info['i'] = count($this->mpdf->images) + 1;
427 $this->mpdf->images[$file] = $info;
438 return $this->imageError($file, $firsttime, 'Error parsing PNG identifier');
443 return $this->imageError($file, $firsttime, 'Incorrect PNG file (no IHDR block found)');
446 $w = $this->fourBytesToInt(substr($data, 16, 4));
447 $h = $this->fourBytesToInt(substr($data, 20, 4));
453 // if($bpc>8) { $errpng = 'not 8-bit depth'; } // mPDF 6 Allow through to be handled as native PNG
487 // incl. single-color tarnsparency, depending which type of handling occurs later
505 $ppUx = $this->fourBytesToInt(substr($data, $j + 4, 4)); // horizontal pixels per meter, usually set to zero
514 if ($j && strpos($data, 'sRGB') === false) { // sRGB colorspace - overrides gAMA
515 $gAMA = $this->fourBytesToInt(substr($data, $j + 4, 4)); // Gamma value times 100000
518 // http://www.libpng.org/pub/png/spec/1.2/PNG-Encoders.html
523 // Test Case - image(s) on http://www.w3.org/TR/CSS21/intro.html - PNG has gAMA set as 1.45454
528 // See test different gamma chunks at http://www.libpng.org/pub/png/pngsuite-all-good.html
541 //$j = strpos($data,'sRGB'); // sRGB colorspace - overrides gAMA
545 if ($firsttime && ($colspace === 'DeviceRGB' || $colspace === 'Indexed') && ($this->mpdf->PDFX || $this->mpdf->restrictColorSpace === 3)) {
547 // Convert to CMYK image stream - nominally returned as type='png'
548 $info = $this->convertImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha, $gamma, $ct); // mPDF 5.7.2 Gamma correction
549 if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) {
550 $this->mpdf->PDFAXwarnings[] = sprintf('PNG image may not use RGB color space - %s - (Image converted to CMYK. NB This will alter the colour profile of the image.)', $file);
553 } elseif ($firsttime && ($colspace === 'DeviceRGB' || $colspace === 'Indexed') && $this->mpdf->restrictColorSpace === 1) {
557 // Convert to Grayscale image stream - nominally returned as type='png'
558 $info = $this->convertImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha, $gamma, $ct); // mPDF 5.7.2 Gamma correction
560 } elseif (($this->mpdf->PDFA || $this->mpdf->PDFX) && $pngalpha) {
563 if ($this->mpdf->restrictColorSpace === 1) { // Grayscale
564 $info = $this->convertImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha, $gamma, $ct); // mPDF 5.7.2 Gamma correction
565 } elseif ($this->mpdf->restrictColorSpace === 3) { // CMYK
566 $info = $this->convertImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha, $gamma, $ct); // mPDF 5.7.2 Gamma correction
567 } elseif ($this->mpdf->PDFA) { // RGB
568 $info = $this->convertImage($data, $colspace, 'DeviceRGB', $w, $h, $ppUx, $pngalpha, $gamma, $ct); // mPDF 5.7.2 Gamma correction
570 if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) {
571 $this->mpdf->PDFAXwarnings[] = sprintf('Transparency (alpha channel) not permitted in PDFA or PDFX files - %s - (Image converted to one without transparency.)', $file);
578 return $this->imageError($file, $firsttime, sprintf('GD library with PNG support required for image (%s)', $errpng));
583 return $this->imageError($file, $firsttime, sprintf('Error creating GD image from PNG file (%s)', $errpng));
589 $tempfile = $this->cache->tempFilename('_tempImgPNG' . md5($file) . random_int(1, 10000) . '.png');
593 if ($this->mpdf->PDFA) {
594 throw new \Mpdf\MpdfException(sprintf('PDFA1-b does not permit images with alpha channel transparency (%s).', $file));
608 $n = $this->fourBytesToInt(substr($data, $p - 4, 4));
619 } // 0-255
631 $n = $this->fourBytesToInt(substr($data, $p - 4, 4));
634 $trns = [$this->translateValue(substr($t, 0, 2), $bpc)];
637 $trns[0] = $this->translateValue(substr($t, 0, 2), $bpc);
638 $trns[1] = $this->translateValue(substr($t, 2, 2), $bpc);
639 $trns[2] = $this->translateValue(substr($t, 4, 2), $bpc);
668 imagesetpixel($imgalpha, $xpx, $ypx, 255 - ($alpha * 2));
675 // imagegammacorrect() removes the alpha channel data in $im - (I think this is a bug in PHP)
680 $tempfile_alpha = $this->cache->tempFilename('_tempMskPNG' . md5($file) . random_int(1, 10000) . '.png');
685 return $this->imageError($file, $firsttime, 'Failed to create temporary image file (' . $tempfile_alpha . ') parsing PNG image with alpha channel (' . $errpng . ')');
697 return $this->imageError($file, $firsttime, 'Failed to create temporary image file (' . $tempfile . ') parsing PNG image with alpha channel (' . $errpng . ')');
701 $minfo = $this->getImage($tempfile_alpha, false);
705 return $this->imageError($file, $firsttime, 'Error parsing temporary file (' . $tempfile_alpha . ') created with GD library to parse PNG image');
708 $imgmask = count($this->mpdf->images) + 1;
711 $this->mpdf->images[$tempfile_alpha] = $minfo;
713 $info = $this->getImage($tempfile, false);
717 return $this->imageError($file, $firsttime, 'Error parsing temporary file (' . $tempfile . ') created with GD library to parse PNG image');
722 $info['set-dpi'] = $ppUx;
726 $info['i'] = count($this->mpdf->images) + 1;
728 $this->mpdf->images[$file] = $info;
734 // No alpha/transparency set (but cannot read directly because e.g. bit-depth != 8, interlaced etc)
740 $n = $this->fourBytesToInt(substr($data, ($p - 8), 4));
742 $icc = substr($data, ($p + $nullsep + 2), ($n - ($nullsep + 2)));
775 return $this->imageError($file, $firsttime, 'Failed to create temporary image file (' . $tempfile . ') parsing PNG image (' . $errpng . ')');
778 $info = $this->getImage($tempfile, false);
781 return $this->imageError($file, $firsttime, 'Error parsing temporary file (' . $tempfile . ') created with GD library to parse PNG image');
785 $info['set-dpi'] = $ppUx;
789 $info['i'] = count($this->mpdf->images) + 1;
795 $this->mpdf->images[$file] = $info;
811 $n = $this->fourBytesToInt(substr($data, $p, 4));
841 $icc = substr($data, $p + $nullsep + 2, $n - ($nullsep + 2));
860 } elseif (preg_match('/[a-zA-Z]{4}/', $type)) {
863 return $this->imageError($file, $firsttime, 'Error parsing PNG image data');
869 return $this->imageError($file, $firsttime, 'Error parsing PNG image data - no IDAT data found');
873 return $this->imageError($file, $firsttime, 'Error parsing PNG image data - missing colour palette');
883 $info['set-dpi'] = $ppUx;
888 return $this->imageError($file, $firsttime, 'Error parsing or converting PNG image');
892 $info['i'] = count($this->mpdf->images) + 1;
894 $this->mpdf->images[$file] = $info;
909 $tempfile = $this->cache->tempFilename('_tempImgPNG' . md5($file) . random_int(1, 10000) . '.png');
917 return $this->imageError($file, $firsttime, 'Error creating temporary image object when using GD library to parse GIF image');
919 $this->mpdf->imageVars['tempImage'] = ob_get_contents();
922 $info = $this->getImage($tempimglnk, false);
924 return $this->imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse GIF image');
930 return $this->imageError($file, $firsttime, 'Error creating temporary file (' . $tempfile . ') when using GD library to parse GIF image');
932 $info = $this->getImage($tempfile, false);
934 return $this->imageError($file, $firsttime, 'Error parsing temporary file (' . $tempfile . ') created with GD library to parse GIF image');
941 $info['i'] = count($this->mpdf->images) + 1;
943 $this->mpdf->images[$file] = $info;
948 return $this->imageError($file, $firsttime, 'Error creating GD image file from GIF image');
956 $gif->loadFile($data, 0);
959 $bgColor = -1;
963 if (isset($gif->m_img->m_gih->m_bLocalClr) && $gif->m_img->m_gih->m_bLocalClr) {
964 $nColors = $gif->m_img->m_gih->m_nTableSize;
965 $pal = $gif->m_img->m_gih->m_colorTable->toString();
966 if ((isset($bgColor)) && $bgColor !== -1) { // mPDF 5.7.3
967 $bgColor = $gif->m_img->m_gih->m_colorTable->colorIndex($bgColor);
970 } elseif (isset($gif->m_gfh->m_bGlobalClr) && $gif->m_gfh->m_bGlobalClr) {
971 $nColors = $gif->m_gfh->m_nTableSize;
972 $pal = $gif->m_gfh->m_colorTable->toString();
973 if ((isset($bgColor)) && $bgColor != -1) {
974 $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor);
981 if (isset($gif->m_img->m_bTrans) && $gif->m_img->m_bTrans && ($nColors > 0)) {
982 $trns = [$gif->m_img->m_nTrans];
985 $gifdata = $gif->m_img->m_data;
986 $w = $gif->m_gfh->m_nWidth;
987 $h = $gif->m_gfh->m_nHeight;
988 $gif->ClearData();
991 return $this->imageError($file, $firsttime, 'Error parsing GIF image - missing colour palette');
994 if ($this->mpdf->compress) {
995 $gifdata = $this->gzCompress($gifdata);
1003 $info['i'] = count($this->mpdf->images) + 1;
1005 $this->mpdf->images[$file] = $info;
1012 if ($this->bmp === null) {
1013 $this->bmp = new Bmp($this->mpdf);
1016 $info = $this->bmp->_getBMPimage($data, $file);
1018 return $this->imageError($file, $firsttime, $info['error']);
1022 $info['i'] = count($this->mpdf->images) + 1;
1024 $this->mpdf->images[$file] = $info;
1031 if ($this->wmf === null) {
1032 $this->wmf = new Wmf($this->mpdf, $this->colorConverter);
1035 $wmfres = $this->wmf->_getWMFimage($data);
1039 return $this->imageError($file, $firsttime, $wmfres[1]);
1041 return $this->imageError($file, $firsttime, 'Error parsing WMF image');
1045 $info['i'] = count($this->mpdf->formobjects) + 1;
1047 $this->mpdf->formobjects[$file] = $info;
1051 } else { // UNKNOWN TYPE - try GD imagecreatefromstring
1062 return $this->imageError($file, $firsttime, 'Error parsing image file - image type not recognised, and not supported by GD imagecreate');
1065 $tempfile = $this->cache->tempFilename('_tempImgPNG' . md5($file) . random_int(1, 10000) . '.png');
1074 return $this->imageError($file, $firsttime, 'Error creating temporary file (' . $tempfile . ') when using GD library to parse unknown image type');
1077 $info = $this->getImage($tempfile, false);
1083 return $this->imageError($file, $firsttime, 'Error parsing temporary file (' . $tempfile . ') created with GD library to parse unknown image type');
1088 $info['i'] = count($this->mpdf->images) + 1;
1090 $this->mpdf->images[$file] = $info;
1097 return $this->imageError($file, $firsttime, 'Error parsing image file - image type not recognised');
1103 return $this->imageError($file, $firsttime, 'GD library needed to parse image files');
1106 if ($this->mpdf->PDFA || $this->mpdf->PDFX) {
1123 if ($colspace === 'Indexed') { // generate Alpha channel values from tRNS - only from PNG
1128 $n = $this->fourBytesToInt(substr($data, $p - 4, 4));
1139 } // 0-255
1149 $n = $this->fourBytesToInt(substr($data, $p - 4, 4));
1152 $trns = [$this->translateValue(substr($t, 0, 2), $bpc)];
1155 $trns[0] = $this->translateValue(substr($t, 0, 2), $bpc);
1156 $trns[1] = $this->translateValue(substr($t, 2, 2), $bpc);
1157 $trns[2] = $this->translateValue(substr($t, 4, 2), $bpc);
1185 $mimgdata .= chr(255 - ($alpha * 2));
1202 if (!$this->mpdf->PDFA && !$this->mpdf->PDFX && !$mask) { // mPDF 6 added NOT mask
1205 $n = $this->fourBytesToInt(substr($data, ($p - 4), 4));
1208 $trns = [$this->translateValue(substr($t, 0, 2), $bpc)];
1210 $trns[0] = $this->translateValue(substr($t, 0, 2), $bpc);
1211 $trns[1] = $this->translateValue(substr($t, 2, 2), $bpc);
1212 $trns[2] = $this->translateValue(substr($t, 4, 2), $bpc);
1215 $col = $this->colorModeConverter->rgb2cmyk([3, $trns[0], $trns[1], $trns[2]]);
1235 $col = $this->colorModeConverter->rgb2cmyk([3, $r, $g, $b]);
1264 $col = $this->colorModeConverter->rgb2cmyk([3, $r, $g, $b]);
1275 $c4--;
1288 $c--;
1307 $imgdata = $this->gzCompress($imgdata);
1311 $info['set-dpi'] = $dpi;
1314 $mimgdata = $this->gzCompress($mimgdata);
1318 $minfo['set-dpi'] = $dpi;
1321 $imgmask = count($this->mpdf->images) + 1;
1323 $this->mpdf->images[$tempfile] = $minfo;
1337 $p += $this->twoBytesToInt(substr($data, $p, 2)); // Length of initial marker block
1342 $p += $this->twoBytesToInt(substr($data, $p + 2, 2)) + 2; // Length of marker block
1360 $h = $this->twoBytesToInt(substr($hdr, 3, 2));
1361 $w = $this->twoBytesToInt(substr($hdr, 5, 2));
1377 * Corrects 2-byte integer to 8-bit depth value
1380 * So why do we only need to correct 16-bit tRNS and NOT 2 or 4-bit???
1384 $n = $this->twoBytesToInt($s);
1397 * Read a 4-byte integer from string
1406 * Read a 2-byte integer from string
1416 throw new \Mpdf\MpdfException('gzcompress is not available. install ext-zlib extension.');
1423 * Throw an exception and save re-trying image URL's which have already failed
1427 $this->failedImages[$file] = true;
1429 if ($firsttime && ($this->mpdf->showImageErrors || $this->mpdf->debug)) {
1433 $this->logger->warning(sprintf('%s (%s)', $msg, $file), ['context' => LogContext::IMAGES]);