[image_scaleDisplay]

Description

Link: [image_scaleDisplay]
Author: Marc Pinnell
Category: Image
Version: 8.5.x
License: Public Domain
Posted: Mar. 17, 2009
Updated: Apr. 22, 2009
More by this author...

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.

Parameters

-height string, required Max height, in pixels, of the rectangle the image needs to fit within.
-source string, required Path to the source image.
-width string, required Max width, in pixels, of the rectangle the image needs to fit within.

Sample Usage

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

	if(file_exists('image.jpg'));
	
		#imgSize = image_scaleDisplay(
			-source=image.jpg,
			-width=290,
			-height=250
			);
		'<img src="image.jpg" '#imgSize' />';
	
	/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.
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[//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;

<img src="myImg.tiff" [$imgSize] alt="Description my sized image" />


Latest version available from <http://tagSwap.net/image_scaleDisplay>.

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

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

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net