Lasso Soft Inc. > Home

[image_scaleDisplay]

Linkimage_scaleDisplay
AuthorMarc Pinnell
CategoryImage
Version8.5.x
LicensePublic Domain
Posted17 Mar 2009
Updated22 Apr 2009
More by this author...

Description

Calculates max height and width of an image within the given dimensions, maintaining the aspect ratio of the original image. Returns a width="xx" height="xx" string for use in an image tag. Requires [math_proportion], available here.

Sample Usage

inline(
	-username='xxxxxx', 
	-password='xxxxxx' ,
	-nothing
	);

	if(file_exists('image.jpg'));
	
		#imgSize = image_scaleDisplay(
			-source=image.jpg,
			-width=290,
			-height=250
			);
		'';
	
	/if;

/inline;

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.

[//lasso
/*----------------------------------------------------------------------------

[image_scaleDisplay]
Scales the specified image within the given dimensions if the image doesn\'t fit.

Author: Marc Pinnell (Based almost entirely on Jason Huck's work)
Last Modified: March 17, 2009
License: Public Domain

Description:
Calculates max height and width of an image within the given dimensions, maintaining the aspect 
ratio of the original image. Returns a width="xx" height="xx" string for use in an image tag.
Requires [math_proportion], available here.


Sample Usage:
var('imgSize' = string);
inline(
	-username='xxxxxx',
	-password='xxxxxx'	
	);
	$imgSize = image_scaleDisplay(
					-source='myImg.tiff',
					-width=300,
					-height=300
					);
/inline;

Description my sized image


Latest version available from .

----------------------------------------------------------------------------*/
		

define_tag(
	'scaleDisplay',
	-namespace='image_',
	-priority='replace',
	-required='source',
	-type='string',
	-required='width',
	-type='integer',
	-required='height',
	-type='integer',
	-description='Scales the specified image within the given dimensions if the image doesn\'t fit and outputs a width/height string for use in image tag.'
);		

	local('img') = image(#source);
	local(
		'mW' = @#width,
		'mH' = @#height,
		'oW' = @#img->width,
		'oH' = @#img->height,
		'nW' = integer,
		'nH' = integer,
		'imgSize' = string
	);
	
	if(#oW > #width || #oH > #height);		//check to see if either dimension is too large
		//Something is too big, scale it!
		if(#oW >= #oH);
			#nW = #mW;
			#nH = math_proportion(#oW,#oH,#nW,'x');
			
			if(#nH > #mH);
				#nH = #mH;
				#nW = math_proportion(#oW,#oH,'x',#nH);
			/if;		
		else;
			#nH = #mH;
			#nW = math_proportion(#oW,#oH,'x',#nH);
			
			if(#nW > #mW);
				#nW = #mW;
				#nH = math_proportion(#oW,#oH,#nW,'x');
			/if;
		/if;
	else;
		//It fits, leave it alone
		#nW = #oW;
		#nH = #oH;
	/if;

	#imgSize += 'width="'#nW'" height="'#nH'"';
	
	return(@#imgSize);
	
/define_tag;
]

Related Tags

Comments

No comments

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