[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/include/fpdf/ -> myFpdf.php (source)

   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  
  10  // $Id: pmvfpdf.php,v 0.5 2006/08/15 10:01:22 cmil_ Exp $

  11  require  (INCLUDE_PATH."/libs/fpdf/fpdf.php");
  12  //require (INCLUDE_PATH."/libs/fpdf/ufpdf.php");

  13  //require (INCLUDE_PATH."/libs/tcpdf/tcpdf_php4/tcpdf.php");//TCPDF

  14  
  15  // Extend fpdf fonctionality (type image pngpmv with is content)

  16  class myFPDF extends FPDF {
  17  //class myFPDF extends TCPDF {

  18  
  19      var $pmvPos = 0;
  20  
  21      // Same in fpdf with a parameter $fileContent

  22  	function Image($file, $x, $y, $w = 0, $h = 0, $type = '', $link = '', $fileContent = '') {
  23              //Put an image on the page

  24                  if (!isset ($this->images[$file])) {
  25              //First use of image, get info

  26              if ($type == '') {
  27                  $pos = strrpos($file, '.');
  28                  if (!$pos)
  29                      $this->Error('Image file has no extension and no type was specified: '.$file);
  30                  $type = substr($file, $pos +1);
  31              }
  32              $type = strtolower($type);
  33              $mqr = get_magic_quotes_runtime();
  34              set_magic_quotes_runtime(0);
  35              if ($type == 'jpg' || $type == 'jpeg')
  36                  $info = $this->_parsejpg($file);
  37              elseif ($type == 'png') $info = $this->_parsepng($file);
  38              else {
  39                  //Allow for additional formats

  40                  $mtd = '_parse'.$type;
  41                  if (!method_exists($this, $mtd))
  42                      $this->Error('Unsupported image type: '.$type);
  43                  // Send new parameter

  44                  $info = $this-> $mtd ($file, $fileContent);
  45              }
  46              set_magic_quotes_runtime($mqr);
  47              $info['i'] = count($this->images) + 1;
  48              $this->images[$file] = $info;
  49          } else
  50              $info = $this->images[$file];
  51          //Automatic width and height calculation if needed

  52          if ($w == 0 && $h == 0) {
  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  
  66      // function like fread with a string (not a file)

  67  	function mfread($str, $lg) {
  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          //Read a 4-byte integer from file

  75          $a = unpack('Ni', $this->mfread($f, 4));
  76          return $a['i'];
  77      }
  78      
  79      // Parse png from a string $fileContent

  80      // write from _parsepng of fpdf

  81      // If ok return an array with all values

  82      // else if error return the error message 

  83  	function _parsepngpmv($fileName, $fileContent) {
  84          // Reset read position

  85          $this->pmvPos = 0;
  86          //Extract info from a PNG file

  87          $f = $fileContent;
  88          //     $f=fopen($file,'rb');

  89          //     if(!$f)

  90          if ($f == null)
  91              return('Can\'t open image file: '.$fileName);
  92  
  93          //Check signature

  94          if ($this->mfread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  95              return('Not a PNG file: '.$fileName);
  96          }
  97          //Read header chunk

  98          $this->mfread($f, 4);
  99          if ($this->mfread($f, 4) != 'IHDR') {
 100              return('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              return('16-bit depth not supported: '.$fileName);
 107          }
 108          $ct = ord($this->mfread($f, 1));
 109          if ($ct == 0)
 110              $colspace = 'DeviceGray';
 111          elseif ($ct == 2) $colspace = 'DeviceRGB';
 112          elseif ($ct == 3) $colspace = 'Indexed';
 113          else
 114              return('Alpha channel not supported: '.$fileName);
 115          if (ord($this->mfread($f, 1)) != 0)
 116              return('Unknown compression method: '.$fileName);
 117          if (ord($this->mfread($f, 1)) != 0)
 118              return('Unknown filter method: '.$fileName);
 119          if (ord($this->mfread($f, 1)) != 0)
 120              return('Interlacing not supported: '.$fileName);
 121          $this->mfread($f, 4);
 122          $parms = '/DecodeParms <</Predictor 15 /Colors '. ($ct == 2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
 123          //Scan chunks looking for palette, transparency and image data

 124          $pal = '';
 125          $trns = '';
 126          $data = '';
 127          do {
 128              $n = $this->m_freadint($f);
 129              $type = $this->mfread($f, 4);
 130              if ($type == 'PLTE') {
 131                  //Read palette

 132                  $pal = $this->mfread($f, $n);
 133                  $this->mfread($f, 4);
 134              }
 135              elseif ($type == 'tRNS') {
 136                  //Read transparency info

 137                  $t = $this->mfread($f, $n);
 138                  if ($ct == 0)
 139                      $trns = array (ord(substr($t, 1, 1)));
 140                  elseif ($ct == 2) $trns = array (ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
 141                  else {
 142                      $pos = strpos($t, chr(0));
 143                      if ($pos !== false)
 144                          $trns = array ($pos);
 145                  }
 146                  $this->mfread($f, 4);
 147              }
 148              elseif ($type == 'IDAT') {
 149                  //Read image data block

 150                  $data .= $this->mfread($f, $n);
 151                  $this->mfread($f, 4);
 152              }
 153              elseif ($type == 'IEND') break;
 154              else
 155                  $this->mfread($f, $n +4);
 156          } while ($n);
 157          if ($colspace == 'Indexed' && empty ($pal))
 158              return('Missing palette in '.$fileName);
 159          //    fclose($f);

 160          return array ('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
 161      }
 162  
 163  }
 164  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics