Lasso Soft Inc. > Home

[image_display]

Linkimage_display
AuthorJason Huck
CategoryImage
Version8.x
LicensePublic Domain
Posted26 Oct 2005
Updated15 Feb 2008
More by this author...

Description

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.

Sample Usage

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

-> 

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.

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' = '');
	
	return(#out);
/define_tag;

Comments

18 Feb 2008, Jason Huck

Re: max size

No, it doesn't do this as currently written, but it would be easy enough to add.

18 Feb 2008, Dominique Guardiola Falco

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?

15 Feb 2008, Jason Huck

Updated

Updated to include options for the following HTML attributes: id, class, title, alt.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft