[image_scalewithin]

Description

Link: [image_scalewithin]
Author: Jason Huck
Category: Image
Version: 8.x
License: Public Domain
Posted: Jan. 16, 2006
Updated: Sep. 10, 2007
More by this author...
Scales the specified image within the given dimensions, maintaining the aspect ratio of the original image. Requires [math_proportion], available here.

Parameters

-source string, required Path to the source image.
-target string, required Path, including name, of the target image (the one to be created).
-width integer, required Width, in pixels, of the rectangle the scaled image should fit within.
-height integer, required Height, in pixels, of the rectangle the scaled image should fit within.

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.
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
49
50
51
52
53
54
55
56
57
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

09/10/2007, Jason Huck
Bug Fix
Corrected an issue that would sometimes set the new width to the wrong value.
08/19/2006, Jason Huck
Bug Fix
Corrected an issue where the height might not always be constrained properly. Thanks to Mason Miller for this fix!
03/16/2006, Alex 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
Email:


Password:



Newest

Most Popular