Пример #1
0
 /**
  * getimagesize doesn't give a good size for 32bit BMP image v5
  *
  * @param string $filename
  * @return array The same format as getimagesize($filename)
  */
 public static function dompdf_getimagesize($filename, $context = null)
 {
     static $cache = array();
     if (isset($cache[$filename])) {
         return $cache[$filename];
     }
     list($width, $height, $type) = getimagesize($filename);
     // Custom types
     $types = array(IMAGETYPE_JPEG => "jpeg", IMAGETYPE_GIF => "gif", IMAGETYPE_BMP => "bmp", IMAGETYPE_PNG => "png");
     $type = isset($types[$type]) ? $types[$type] : null;
     if ($width == null || $height == null) {
         $data = file_get_contents($filename, null, $context, 0, 26);
         if (substr($data, 0, 2) === "BM") {
             $meta = unpack('vtype/Vfilesize/Vreserved/Voffset/Vheadersize/Vwidth/Vheight', $data);
             $width = (int) $meta['width'];
             $height = (int) $meta['height'];
             $type = "bmp";
         } else {
             if (strpos(file_get_contents($filename), "<svg") !== false) {
                 $doc = new \Svg\Document();
                 $doc->loadFile($filename);
                 list($width, $height) = $doc->getDimensions();
                 $type = "svg";
             }
         }
     }
     return $cache[$filename] = array($width, $height, $type);
 }
Пример #2
0
 /**
  * add a PNG image into the document, from a file
  * this should work with remote files
  */
 function addSvgFromFile($file, $x, $y, $w = 0, $h = 0)
 {
     $doc = new \Svg\Document();
     $doc->loadFile($file);
     $dimensions = $doc->getDimensions();
     $this->save();
     $this->transform(array($w / $dimensions["width"], 0, 0, $h / $dimensions["height"], $x, $y));
     $surface = new \Svg\Surface\SurfaceCpdf($doc, $this);
     $doc->render($surface);
     $this->restore();
 }