4 * @link http://dompdf.github.com/
5 * @author Benj Carson <benjcarson@digitaljunkies.ca>
6 * @author Fabien Ménager <fabien.menager@gmail.com>
7 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
9 namespace Dompdf\FrameDecorator
;
13 use Dompdf\FontMetrics
;
14 use Dompdf\Image\Cache
;
17 * Decorates frames for image layout and rendering
21 class Image
extends AbstractFrameDecorator
25 * The path to the image file (note that remote images are
26 * downloaded locally to Options:tempDir).
30 protected $_image_url;
33 * The image's file error message
37 protected $_image_msg;
42 * @param Frame $frame the frame to decorate
43 * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls)
45 function __construct(Frame
$frame, Dompdf
$dompdf)
47 parent
::__construct($frame, $dompdf);
48 $url = $frame->get_node()->getAttribute("src");
50 $debug_png = $dompdf->get_option("debug_png");
51 if ($debug_png) print '[__construct ' . $url . ']';
53 list($this->_image_url
, /*$type*/, $this->_image_msg
) = Cache
::resolve_url(
55 $dompdf->get_protocol(),
57 $dompdf->get_base_path(),
61 if (Cache
::is_broken($this->_image_url
) &&
62 $alt = $frame->get_node()->getAttribute("alt")
64 $style = $frame->get_style();
65 $style->width
= (4 / 3) * $dompdf->getFontMetrics()->getTextWidth($alt, $style->font_family
, $style->font_size
, $style->word_spacing
);
66 $style->height
= $dompdf->getFontMetrics()->getFontHeight($style->font_family
, $style->font_size
);
71 * Return the image's url
73 * @return string The url of this image
75 function get_image_url()
77 return $this->_image_url
;
81 * Return the image's error message
83 * @return string The image's error message
85 function get_image_msg()
87 return $this->_image_msg
;