5 * Plugin to generate an <img ... /> tag.
9 * @author Paul M. Jones <pmjones@ciaweb.net>
11 * @license http://www.gnu.org/copyleft/lesser.html LGPL
13 * @version $Id: Savant3_Plugin_image.php,v 1.7 2005/08/12 14:34:09 pmjones Exp $
19 * Plugin to generate an <img ... /> tag.
21 * Support for alpha transparency of PNG files in Microsoft IE added by
22 * Edward Ritter; thanks, Edward.
26 * @author Paul M. Jones <pmjones@ciaweb.net>
30 class Savant3_Plugin_image
extends Savant3_Plugin
41 protected $documentRoot = null;
45 * The base directory for images within the document root.
52 protected $imageDir = null;
56 * Outputs an <img ... /> tag.
58 * Microsoft IE alpha PNG support added by Edward Ritter.
63 * The path to the image on the local file system
64 * relative to $this->imageDir.
67 * Alternative descriptive text for the image;
68 * defaults to the filename of the image.
71 * The border width for the image; defaults to zero.
74 * The displayed image width in pixels; defaults to
75 * the width of the image.
78 * The displayed image height in pixels; defaults to
79 * the height of the image.
81 * @return string An <img ... /> tag.
84 public function image($file, $alt = null, $height = null, $width = null, $attr = null)
86 // is the document root set?
87 if (is_null($this->documentRoot
) && isset($_SERVER ['DOCUMENT_ROOT'])) {
89 $this->documentRoot
= $_SERVER ['DOCUMENT_ROOT'];
92 // make sure there's a DIRECTORY_SEPARATOR between the docroot
94 if (substr($this->documentRoot
, - 1) != DIRECTORY_SEPARATOR
&& substr($this->imageDir
, 0, 1) != DIRECTORY_SEPARATOR
) {
95 $this->documentRoot
.= DIRECTORY_SEPARATOR
;
98 // make sure there's a separator between the imageDir and the
100 if (substr($this->imageDir
, - 1) != DIRECTORY_SEPARATOR
&& substr($file, 0, 1) != DIRECTORY_SEPARATOR
) {
101 $this->imageDir
.= DIRECTORY_SEPARATOR
;
104 // the image file type code (PNG = 3)
107 // get the file information
110 if (strpos($file, '://') === false) {
111 // no "://" in the file, so it's local
112 $file = $this->imageDir
. $file;
113 $tmp = $this->documentRoot
. $file;
114 $info = @getimagesize
($tmp);
116 // don't attempt to get file info from streams, it takes
121 // did we find the file info?
122 if (is_array($info)) {
123 // capture type info regardless
126 // capture size info where both not specified
127 if (is_null($width) && is_null($height)) {
136 // is the file a PNG? if so, check user agent, we will need to
137 // make special allowances for Microsoft IE.
138 if (stristr($_SERVER ['HTTP_USER_AGENT'], 'MSIE') && $type === 3) {
139 // support alpha transparency for PNG files in MSIE
140 $html = '<span style="position: relative;';
143 $html .= ' height: ' . $height . 'px;';
147 $html .= ' width: ' . $width . 'px;';
150 $html .= ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
151 $html .= "(src='" . htmlspecialchars($file) . "',sizingMethod='scale');\"";
152 $html .= ' title="' . htmlspecialchars($alt) . '"';
154 $html .= $this->Savant
->htmlAttribs($attr);
159 // not IE, so build a normal image tag.
161 $html .= ' src="' . htmlspecialchars($file) . '"';
163 // add the alt attribute
165 $alt = basename($file);
168 $html .= ' alt="' . htmlspecialchars($alt) . '"';
170 // add the height attribute
172 $html .= ' height="' . htmlspecialchars($height) . '"';
175 // add the width attribute
177 $html .= ' width="' . htmlspecialchars($width) . '"';
180 $html .= $this->Savant
->htmlAttribs($attr);