[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 <?php 2 /* 3 * phpMyVisites : website statistics and audience measurements 4 * Copyright (C) 2002 - 2006 5 * http://www.phpmyvisites.net/ 6 * phpMyVisites is free software (license GNU/GPL) 7 * Authors : phpMyVisites team 8 */ 9 // $Id: pmvfpdf.php,v 0.5 2006/08/15 10:01:22 cmil_ Exp $ 10 require (INCLUDE_PATH . "/libs/fpdf/chinese.php"); 11 // Extend fpdf fonctionality (type image pngpmv with is content) 12 class myFPDF extends PDF_Chinese 13 { 14 var $pmvPos = 0; 15 // Same in fpdf with a parameter $fileContent 16 function Image($file, $x, $y, $w = 0, $h = 0, $type = '', $link = '', $fileContent = '') 17 { 18 // Put an image on the page 19 if (!isset ($this->images[$file])) 20 { 21 // First use of image, get info 22 if ($type == '') 23 { 24 $pos = strrpos($file, '.'); 25 if (!$pos) 26 $this->Error('Image file has no extension and no type was specified: ' . $file); 27 $type = substr($file, $pos + 1); 28 } 29 $type = strtolower($type); 30 $mqr = get_magic_quotes_runtime(); 31 set_magic_quotes_runtime(0); 32 if ($type == 'jpg' || $type == 'jpeg') 33 $info = $this->_parsejpg($file); 34 elseif ($type == 'png') $info = $this->_parsepng($file); 35 else 36 { 37 // Allow for additional formats 38 $mtd = '_parse' . $type; 39 if (!method_exists($this, $mtd)) 40 $this->Error('Unsupported image type: ' . $type); 41 // Send new parameter 42 $info = $this->$mtd ($file, $fileContent); 43 } 44 set_magic_quotes_runtime($mqr); 45 $info['i'] = count($this->images) + 1; 46 $this->images[$file] = $info; 47 } 48 else 49 $info = $this->images[$file]; 50 // Automatic width and height calculation if needed 51 if ($w == 0 && $h == 0) 52 { 53 // Put image at 72 dpi 54 $w = $info['w'] / $this->k; 55 $h = $info['h'] / $this->k; 56 } 57 if ($w == 0) 58 $w = $h * $info['w'] / $info['h']; 59 if ($h == 0) 60 $h = $w * $info['h'] / $info['w']; 61 $this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q', $w * $this->k, $h * $this->k, $x * $this->k, ($this->h - ($y + $h)) * $this->k, $info['i'])); 62 if ($link) 63 $this->Link($x, $y, $w, $h, $link); 64 } 65 // function like fread with a string (not a file) 66 function mfread($str, $lg) 67 { 68 $ret = substr($str, $this->pmvPos, $lg); 69 $this->pmvPos += $lg; 70 return $ret; 71 } 72 // Same as _freadint with a string (not a file) 73 function m_freadint($f) 74 { 75 // Read a 4-byte integer from file 76 $a = unpack('Ni', $this->mfread($f, 4)); 77 return $a['i']; 78 } 79 // Parse png from a string $fileContent 80 // write from _parsepng of fpdf 81 function _parsepngpmv($fileName, $fileContent) 82 { 83 // Reset read position 84 $this->pmvPos = 0; 85 // Extract info from a PNG file 86 $f = $fileContent; 87 // $f=fopen($file,'rb'); 88 // if(!$f) 89 if ($f == null) 90 $this->Error('Can\'t open image file: ' . $fileName); 91 // Check signature 92 if ($this->mfread($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10)) 93 { 94 $this->Error('Not a PNG file: ' . $fileName); 95 } 96 // Read header chunk 97 $this->mfread($f, 4); 98 if ($this->mfread($f, 4) != 'IHDR') 99 { 100 $this->Error('Incorrect PNG file: ' . $fileName); 101 } 102 $w = $this->m_freadint($f); 103 $h = $this->m_freadint($f); 104 $bpc = ord($this->mfread($f, 1)); 105 if ($bpc > 8) 106 { 107 $this->Error('16-bit depth not supported: ' . $fileName); 108 } 109 $ct = ord($this->mfread($f, 1)); 110 if ($ct == 0) 111 $colspace = 'DeviceGray'; 112 elseif ($ct == 2) $colspace = 'DeviceRGB'; 113 elseif ($ct == 3) $colspace = 'Indexed'; 114 else 115 $this->Error('Alpha channel not supported: ' . $fileName); 116 if (ord($this->mfread($f, 1)) != 0) 117 $this->Error('Unknown compression method: ' . $fileName); 118 if (ord($this->mfread($f, 1)) != 0) 119 $this->Error('Unknown filter method: ' . $fileName); 120 if (ord($this->mfread($f, 1)) != 0) 121 $this->Error('Interlacing not supported: ' . $fileName); 122 $this->mfread($f, 4); 123 $parms = '/DecodeParms <</Predictor 15 /Colors ' . ($ct == 2 ? 3 : 1) . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w . '>>'; 124 // Scan chunks looking for palette, transparency and image data 125 $pal = ''; 126 $trns = ''; 127 $data = ''; 128 do 129 { 130 $n = $this->m_freadint($f); 131 $type = $this->mfread($f, 4); 132 if ($type == 'PLTE') 133 { 134 // Read palette 135 $pal = $this->mfread($f, $n); 136 $this->mfread($f, 4); 137 } elseif ($type == 'tRNS') 138 { 139 // Read transparency info 140 $t = $this->mfread($f, $n); 141 if ($ct == 0) 142 $trns = array (ord(substr($t, 1, 1))); 143 elseif ($ct == 2) $trns = array (ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1))); 144 else 145 { 146 $pos = strpos($t, chr(0)); 147 if ($pos !== false) 148 $trns = array ($pos); 149 } 150 $this->mfread($f, 4); 151 } elseif ($type == 'IDAT') 152 { 153 // Read image data block 154 $data .= $this->mfread($f, $n); 155 $this->mfread($f, 4); 156 } elseif ($type == 'IEND') break; 157 else 158 $this->mfread($f, $n + 4); 159 } 160 while ($n); 161 if ($colspace == 'Indexed' && empty ($pal)) 162 $this->Error('Missing palette in ' . $fileName); 163 // fclose($f); 164 return array ('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data); 165 } 166 } 167 168 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |