Lasso Soft Inc. > Home

[image_scalewithin]

Linkimage_scalewithin
AuthorJason Huck
CategoryImage
Version8.x
LicensePublic Domain
Posted16 Jan 2006
Updated10 Sep 2007
More by this author...

Description

Scales the specified image within the given dimensions, maintaining the aspect ratio of the original image. Requires [math_proportion], available here.

Sample Usage

inline(
	-username='xxxxxx',
	-password='xxxxxx'	
);
	image_scalewithin(
		-source='before.tiff',
		-target='after.gif',
		-width=300,
		-height=300
	);
/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.

define_tag(
	'scalewithin',
	-namespace='image_',
	-priority='replace',
	-required='source',
	-type='string',
	-required='target',
	-type='string',
	-required='width',
	-type='integer',
	-required='height',
	-type='integer',
	-description='Scales the specified image within the given dimensions.'
);		
	fail_if(
		!file_exists(#source),
		-1,
		'The specified file could not be found.'
	);
	
	local('img') = image(#source);
	local(
		'mW' = @#width,
		'mH' = @#height,
		'oW' = @#img->width,
		'oH' = @#img->height,
		'nW' = integer,
		'nH' = integer
	);
	
	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;

	#img->scale(
		-width=#nW,
		-height=#nH,
		-thumbnail
	);
	
	#img->save(#target);
/define_tag;

Related Tags

Comments

13 Jan 2009, Steve Piercy

RE: Doesn't get along with Filemaker

This tag uses the file system, not FileMaker, for the source of an image file. Nonetheless you could modify the tag such that you pass an image variable (datatype is an image) from FileMaker, instead of an image filepath, and it will work.

10 Sep 2007, Jason Huck

Bug Fix

Corrected an issue that would sometimes set the new width to the wrong value.

19 Aug 2006, Jason Huck

Bug Fix

Corrected an issue where the height might not always be constrained properly. Thanks to Mason Miller for this fix!

16 Mar 2006, Alexander Pollard

Doesn't get along with Filemaker

I wanted to try to have this dynamically make tumbnails from Filemaker imbedded images. It didn't work.

-A

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