Ejemplo n.º 1
0
 function image($img_url, $x, $y, $w, $h, $resolution = "normal")
 {
     $w = (int) $w;
     $h = (int) $h;
     $img_type = Cache::detect_type($img_url);
     $img_ext = Cache::type_to_ext($img_type);
     if (!isset($this->_imgs[$img_url])) {
         $this->_imgs[$img_url] = $this->_pdf->load_image($img_ext, $img_url, "");
     }
     $img = $this->_imgs[$img_url];
     $y = $this->y($y) - $h;
     $this->_pdf->fit_image($img, $x, $y, 'boxsize={' . "{$w} {$h}" . '} fitmethod=entire');
 }
Ejemplo n.º 2
0
 /**
  * Convert a GIF or BMP image to a PNG image
  *
  * @param string $image_url
  * @param integer $type
  *
  * @throws Exception
  * @return string The url of the newly converted image
  */
 protected function _convert_gif_bmp_to_png($image_url, $type)
 {
     $image_type = Cache::type_to_ext($type);
     $func_name = "imagecreatefrom{$image_type}";
     if (!function_exists($func_name)) {
         throw new Exception("Function {$func_name}() not found.  Cannot convert {$image_type} image: {$image_url}.  Please install the image PHP extension.");
     }
     set_error_handler(array("\\Dompdf\\Helpers", "record_warnings"));
     $im = $func_name($image_url);
     if ($im) {
         imageinterlace($im, false);
         $tmp_dir = $this->_dompdf->get_option("temp_dir");
         $tmp_name = tempnam($tmp_dir, "{$image_type}dompdf_img_");
         @unlink($tmp_name);
         $filename = "{$tmp_name}.png";
         $this->_image_cache[] = $filename;
         imagepng($im, $filename);
         imagedestroy($im);
     } else {
         $filename = Cache::$broken_image;
     }
     restore_error_handler();
     return $filename;
 }
Ejemplo n.º 3
0
 /**
  * Add an image to the pdf.
  * The image is placed at the specified x and y coordinates with the
  * given width and height.
  *
  * @param string $img_url the path to the image
  * @param float $x x position
  * @param float $y y position
  * @param int $w width (in pixels)
  * @param int $h height (in pixels)
  * @param string $resolution
  *
  * @return void
  * @internal param string $img_type the type (e.g. extension) of the image
  */
 function image($img_url, $x, $y, $w, $h, $resolution = "normal")
 {
     $img_type = Cache::detect_type($img_url);
     $img_ext = Cache::type_to_ext($img_type);
     if (!$img_ext) {
         return;
     }
     $func = "imagecreatefrom{$img_ext}";
     $src = @$func($img_url);
     if (!$src) {
         return;
         // Probably should add to $_dompdf_errors or whatever here
     }
     // Scale by the AA factor
     $x *= $this->_aa_factor;
     $y *= $this->_aa_factor;
     $w *= $this->_aa_factor;
     $h *= $this->_aa_factor;
     $img_w = imagesx($src);
     $img_h = imagesy($src);
     imagecopyresampled($this->_img, $src, $x, $y, 0, 0, $w, $h, $img_w, $img_h);
 }