Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created February 16, 2010 10:37
Show Gist options
  • Save nojimage/305444 to your computer and use it in GitHub Desktop.
Save nojimage/305444 to your computer and use it in GitHub Desktop.
for mpdf 4.2. progressive jpeg image path.
Index: mpdf.php
===================================================================
--- mpdf.php (original)
+++ mpdf.php (new)
@@ -8000,16 +8000,25 @@
// JPEG
if ($type == 'jpeg' || $type == 'jpg') {
- $hdr = $this->_jpgHeaderFromString($data);
- if (!$hdr) { return $this->_imageError($file, $firsttime, 'Error parsing JPG header'); }
- $a = $this->_jpgDataFromHeader($hdr);
- $info = array('w'=>$a[0],'h'=>$a[1],'cs'=>$a[2],'bpc'=>$a[3],'f'=>'DCTDecode','data'=>$data);
- $info['type']='jpg';
- if ($firsttime) {
- $info['i']=count($this->images)+1;
- $this->images[$file]=$info;
- }
- return $info;
+
+ $im = @imagecreatefromstring($data);
+ if ($im) {
+ $tempfile = _MPDF_PATH.'tmp/_tempImgPNG'.RAND(1,10000).'.png';
+ imageinterlace($im, false);
+ $check = @imagepng($im, $tempfile);
+ if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse JPEG image'); }
+ $info = $this->_getImage($tempfile, false);
+ if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse JPEG image'); }
+ imagedestroy($im);
+ unlink($tempfile);
+ $info['type']='jpg';
+ if ($firsttime) {
+ $info['i']=count($this->images)+1;
+ $this->images[$file]=$info;
+ }
+ return $info;
+ }
+ else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from JPEG image'); }
}
// PNG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment