[image_display]

Description

Link: [image_display]
Author: Jason Huck
Category: Image
Version: 8.x
License: Public Domain
Posted: Oct. 26, 2005
Updated: Feb. 15, 2008
More by this author...

This tag is useful in cases where an image must be scaled to fit within the HTML of a page and the need to properly include both dimensions outweighs the extra processing time required for the calculation. A perfect example is HTML emails for antiquated clients such as Lotus Notes.

Requires the path to the image and whichever new dimension is known. Optionally accepts an "absolute" param if the generated image tag should use an absolute URL.

Parameters

-filepath string, required The path to the image file.
-width integer, optional The width to which the image will be scaled in the HTML.
-height integer, optional The height to which the image will be scaled in the HTML.
-absolute boolean, optional A true value will create absolute URLs. Defaults to false.
-id string, optional The HTML id attribute to use.
-title string, optional The HTML title attribute to use.
-class string, optional The HTML class attribute to use.
-alt string, optional The HTML alt attribute to use.

Sample Usage

image_display(
    -filepath='/path/to/file.gif',
    -width=200
);

-> <img src="/path/to/file.gif" border="0" alt="" width="200" height="320" />
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
define_tag(
	'display',
	-namespace='image_',
	-req='filepath', -type='string',
	-opt='width', -type='integer',
	-opt='height', -type='integer',
	-opt='absolute', -type='boolean',
	-opt='id',
	-opt='class',
	-opt='title',
	-opt='alt',
	-priority='replace',
	-encodenone,
	-description='Writes an HTML image tag with scaled dimensions. Calculates the correct missing dimension.'
);
	fail_if(
		!file_exists(#filepath),
		-1,
		'Image does not exist.'
	);
	
	local('image') = image(#filepath);
	
	local(
		'oW' = @#image->width,
		'oH' = @#image->height,
		'nW' = (local_defined('width') ? #width | 0),
		'nH' = (local_defined('height') ? #height | 0)
	);
	
	select(true);
		case(#nW == 0 && #nH != 0);
			#nW = (#oW * #nH) / #oH;
			
		case(#nW != 0 && #nH == 0);
			#nH = (#nW * #oH) / #oW;
		
		case(#nW == 0 && #nH == 0);
			#nW = #oW;
			#nH = #oH;
						
	/select;
	
	local('out' = '<img' + (local_defined('id') ? ' id="' + #id + '"') + (local_defined('title') ? ' title="' + #title + '"') + (local_defined('class') ? ' class="' + #class + '"') + ' src="' + (local('absolute') ? 'http://' + server_name) + #filepath + '" border="0" alt="' + local('alt') + '" width="' + #nW + '" height="' + #nH + '" />');
	
	return(#out);
/define_tag;

 

Comments

02/18/2008, Jason Huck
Re: max size
No, it doesn't do this as currently written, but it would be easy enough to add.
02/18/2008, Dominique Guardiola
max size
Can I give this tag both -height and -width , I mean the max height and the max width and it takes the bigger, makes it fit, and the second size follow keeping the ratio ? Is this english?
02/15/2008, Jason Huck
Updated
Updated to include options for the following HTML attributes: id, class, title, alt.
Email:


Password:



Newest

Most Popular