Version: @(#) $Id: html_image_tag_class.php,v 1.17 2008/08/10 02:03:02 mlemos Exp $
HTML image tag generator
Manuel Lemos (mlemos@acm.org)
Copyright © (C) Manuel Lemos 2003
@(#) $Id: html_image_tag_class.php,v 1.17 2008/08/10 02:03:02 mlemos Exp $
This class is meant to generate IMG HTML tag and its attributes for given images.
It can automatically compute the image size to fill the width and height attributes for images defined from locally accessible files.
The class can also generate an image tag with a special source URL that contains the actual image data defined according to RFC 2397. This way it, the image can be embedded in your HTML documents, making it possible to display the HTML documents without requiring external image files.
This may be useful for embeding images in single file HTML pages or including images in HTML e-mail messages without the need to attach the image files to the messages.
The data for embedded images may be supplied from a locally accessible file or from a string that contains the image file binary data.
Set the SRC and other class variables to specify the image details.
Call the GetMarkup function to generate the corresponding HTML IMG tag.
Call the GetFileDataURL function to generate the data URL of a locally accessible image file, so it can be used to embed images in HTML documents.
The GetDataURL function can be used to generate a data URL from string of binary data. The generated data URL may be of any type, not necessarily of an image.
string
''
Pass the image source URL, file name or binary data.
Set this variable with the URL or the name of the image file.
If you specify a local image file but you want the generated image tag to use its full URL, set the full_URI variable to 1 and set the base_url variable to the prefix that needs to prepended to the local file path to generate the expanded URL.
Set this variable to a string of binary data if you want to generate an HTML tag with an embedded image with its data passed explicitily. In this case set both the embedded and from_data variables to 1.
string
''
Pass the alternative text to present in the place of the image.
Set this variable with the text that you want to see displayed in circumstances when the image graphics cannot be presented. Set to an empty string if you do not want to specify an alternative text.
string
''
Pass the title text to display as tool tip.
Set this variable with the text that you want to see displayed as the image tool tip, usually when the user leaves the mouse pointer over the image in a graphical browser. Set to an empty string if you do not want to specify an alternative text.
string
''
Pass the type of vertical alignment of the image relatively the current text line.
Set this variable with either the values 'top', 'middle' or 'top' to specify the image vertical alignment. If you leave the empty string default value, the bottom of the image will appear align with the current text baseline.
int
0
Pass the width of the image to be used when the class is not able to determine it automatically.
Set this variable with the number of pixels of width of the image so the class can use the value when it is not possible to determine the image width automatically, like for instance when is reference a remote image. Set this variable to 0 to tell the class to not generate the width attribute.
int
0
Pass the height of the image to be used when the class is not able to determine it automatically.
Set this variable with the number of pixels of height of the image so the class can use the value when it is not possible to determine the image height automatically, like for instance when is reference a remote image. Set this variable to 0 to tell the class to not generate the height attribute.
string
''
Pass the width of the border around the image. When the image is used in an HTML link, the border is usually drawn with the link color.
Set this variable with a text string that contains the number of pixels of width of the image border. Leaving this variable default empty string will make the class not generate the border attribute, thus letting the browser assume the default border width. If you want to display the image without a border, set this variable to '0'.
string
''
Pass the style attribute to render the image.
Set this variable with a text string that contains the style of the image. Leaving this variable default empty string will make the class not generate the style attribute.
string
''
Pass the CSS class attribute to render the image.
Set this variable with a text string that contains the name of the CSS class of the image. Leaving this variable default empty string will make the class not generate the class attribute.
string
''
Specify the MIME type of the image.
If you are generating an embedded image tag from data, set this variable to the corresponding MIME type for the given image.
When the image has its size and type determined automatically by the class by analysing a locally accessible image file, the class sets this variable to the corresponding MIME type.
'image/gif'
bool
0
Indicate whether the image source needs to be expanded with a base URL prefix.
If you want the generated image tag to be expand by adding a base URL prefix, set this variable to 1 and the set the base_url variable with the URL prefix that you want to prepend to the URL specified by the SRC variable.
string
''
Specify the URL that will serve as prefix to the image file specified by the SRC variable.
If you want to generate an image tag with source URL set for a local image file, set the SRC to the image local file path, set the base_url to the prefix that you want to prepend to the image file path and set the full_URI to 1.
bool
0
Indicate whether the image file is locally accessible.
If the specified image is locally accessible, the class may examine it to retrieve its dimensions. Additionally, the actual image data can be embedded in the generated image HTML tag.
If the image file is not locally accessible, this variable should be set to 1. In this case, the class will use the values specified by the variables WIDTH and HEIGHT as dimensions.
Under some PHP versions with an appropriate configuration, it is possible to use remote images as locally acessible files by specifying the full URL in the SRC variable.
bool
0
Indicate whether the generated image tag should include the actual image data.
If the image specified by the SRC is a locally accessible file, you can set the embedded variable to 1 if you would like the image data to be included in the generated image tag.
bool
0
Indicate whether the data for an embedded image is passed explicitly or it should be read from an image file.
To passed the data of an embedded image explicitly, set either this variable and embedded variable to 1 and then set the SRC variable to a string that contains the image binary data.
int
10000
Specify the maximum length of the buffer to be used when examining locally accessible image files.
Usually the default value of this variable is appropriate to read any type of image files. Change this variable only if you have a special reason to use a different maximum buffer length.
string
''
Store the message that is returned when an error occurs.
Check this variable to understand what happened when a call to any of the class functions has failed.
bool
0
Make the generated image not be visible.
Set this flag when you want to make the image be loaded but not be visible.
bool
0
Generate XHTML compliant HTML.
Set this flag when you want to make the generated HTML be compliant with XHTML.
string GetDataURL(
Generate a data URL from from a binary data string.
Pass to the data argument a string that contains the binary data from which you want to generate the data URL. The mime_type argument should specify the MIME type of the data.
data - String that contains the binary data.
mime_type - MIME type of the binary data. It may be an empty string in case the MIME type of the data is unknown.
A text string that represents the data URL.
string GetFileDataURL(
Generate a data URL of from locally accessible image file.
Pass to the source argument the local file path or an URL of the image source from which you want to generate the corresponding data URL.
source - Local file path or URL of the image source.
A text string that represents the data URL of the specified image file.
If this function fails for some reason, it returns an empty string and the error variable is set to with an error message that explains the reason for the failure.
string GetMarkup()
Generate the HTML IMG tag that represents the image according to the values of the class variables.
Set the SRC and other class variables to specify the image from which you want to generate the corresponding HTML IMG tag.
A text string that is the image HTML IMG tag.
If this function fails for some reason, it returns an empty string and the error variable is set to with an error message that explains the reason for the failure.