Monday, November 08, 2010 at 12:05 AM.

system.verbs.builtins.radio.images.imageRef

on imageRef (imgpath, usemap="", align="", hspace="", vspace="", flFileUrl=false, alt="", height="", width="") {
	<<Changes:
		<<12/27/02; 1:03:48 PM by JES
			<<Add a space and forward slash before closing the img tag. Fixes a validation problem for XHTML pages, and still validates for HTML 4.01 Transitional pages.
		<<7/1/02; 2:30:49 AM by JES
			<<Always add the alt attribute, even if its value is the empty string. It's a required attribute in HTML 4.01.
		<<1/30/02; 5:13:10 PM by JES
			<<Fixed a bug where the height and width attributes could end up with empty values.
		<<1/30/02; 12:25:11 PM by JES
			<<Added optional height and width parameters.
		<<1/28/02; 10:17:22 AM by DW
			<<Added optional alt parameter, if non-empty, add an alt attribute to the image that's generated.
		<<11/25/01; 3:17:27 AM by JES
			<<Implemented a workaround for the character-case issue on Windows, since converting to a filespec doesn't fix the character-case of the filename.
		<<11/22/01; 12:27:38 AM by JES
			<<Commented out some debugging code.
		<<10/13/01; 3:56:07 AM by JES
			<<When generating image URLs, preserve the case of the files on disk: Clients don't care about case, but the static server does, so make sure that the case of the file path in the img tag matches the actual case of the file that's upstreamed.
		<<7/26/01; 3:07:42 PM by JES
			<<Added a leading slash character to the non-file URL, so images will work on sub-pages when accessing the site remotely.
		<<4/18/01; 4:10:59 PM by DW
			<<Moved from myUserLandSuite.
	if imgpath beginswith "/" {
		imgpath = string.delete (imgpath, 1, 1)};
	local (f = user.radio.prefs.wwwfolder + string.replaceall (imgpath, "/", file.getpathchar ()));
	bundle { //correct the case -- the static server is case-sensitive
		local (pc = file.getPathChar ());
		if system.environment.isMac { //MacOS -- convert to a filespec to fix the filename's character-case
			f = string (filespec (f))}
		else { //workaround for windows: use fileloop (f in f) {} to fix the filename's character-case
			fileloop (f in f) {}};
		imgpath = string.replaceAll (string.delete (f, 1, sizeOf (user.radio.prefs.wwwfolder)), pc, "/")};
	if usemap != "" {
		usemap = " usemap=\"#" + usemap + "\""};
	if align != "" {
		align = " align=\"" + align + "\""};
	if hspace != "" {
		hspace = " hspace=\"" + hspace + "\""};
	if vspace != "" {
		vspace = " vspace=\"" + vspace + "\""};
	if true { //alt != ""
		alt = " alt=\"" + alt + "\""};
	local (hw = "");
	bundle { //set hw
		local (adrincache = @system.temp.radio.hwCache.[imgpath], hwlist);
		if defined (adrincache^) and (height == "" and width == "") {
			hw = adrincache^}
		else {
			local (extension = string.nthfield (imgpath, ".", string.countfields (imgpath, ".")));
			case string.lower (extension) {
				"gif" {
					hwlist = html.getGifHeightWidth (f)};
				"jpeg";
				"jpg" {
					hwlist = html.getJpegHeightWidth (f)}};
			try {
				hw = " width=\"" + hwlist [2] + "\" height=\"" + hwlist [1] + "\"";
				adrincache^ = hw;
				if height != "" or width != "" { //height and/or width passed in
					if height != "" and width != "" {
						hw = " width=\"" + width + "\" height=\"" + height + "\""}
					else {
						if height != "" {
							hw = " width=\"" + hwlist [2] + "\" height=\"" + height + "\""};
						if width != "" {
							hw = " width=\"" + width + "\" height=\"" + hwlist [1] + "\""}}}}
			else {
				hw = ""}}};
	local (url);
	if flFileUrl {
		<<workspace.f = f
		url = html.getfileurl (f)}
		<<url = file.fileToUrl (f)
	else {
		url = "/" + imgpath};
	url = radio.images.imageFlowBottleneck (f, url);
	return ("<img src=\"" + url + "\" border=\"0\"" + hw + usemap + align + hspace + vspace + alt + " />")}
<<bundle //test code
	<<webbrowser.displaytext (imageRef ("/system/images/apacheIcons/folder2.gif"))



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.