This page shows samples of how my getImageSize function for ColdFusion works.
You can Download the function at the bottom of the page.

This function will return information about an image passed to it depending on the arguments passed. The function will return the appropriate dimensions of the image resized to the value set in the MaxSize field.

Returns "Width,Height" as comma delimited list of integers, Width as integer, or Height as integer

    ImageUsed - This is the path to the image being tested.
    MaxSize - This is the maximum size that the image should be in the designated dimension.
    ReturnValue - This is the value that you want returned, either the width (default), height, or both in a comma delimited list.
    OnlyDimension - Setting this to height or width will only resize that dimension. Default is both.
    Enlarge - If the dimensions are less than the MaxSize argument, should the image be enlarged? Default is Both.
      none - Neither dimension should be enlarged.
      both - Both dimensions should be enlarged. The image will have it's shortest dimension = MaxSize
      one - Only one dimension will be enlarged, whichever is larger. This ensures that the largest dimension = MaxSize
      height - Only the height will be enlarged. This causes the image to have the height = MaxSize
      width - Only the width will be enlarged. This causes the image to have the width = MaxSize
    PrependPath - For images in another folder or another disk, prepend this path.


Original Image Size:
  • ImgA = 640 wide x 480 high
  • ImgB = 50 wide x 100 high
  • ImgC = 300 wide x 120 high
  • ImgD = 150 wide x 240 high
  • FUNCTION ImgA ImgB ImgC ImgD COMMENTS
    ImageUsed,MaxSize,ReturnValue,OnlyDimension,Enlarge w,h w,h w,h w,h Returns "Width,Height"
    getImageSize(strImage,0,"both") 640,480 50,100 300,120 150,240 Returns the actual dimensions of the image.
     
    getImageSize(strImage,200,"both","both","none") 200,150 50,100 200,80 125,200 Resizes the image so that the longest dimension is 200 pixels, but does not enlarge the image.
    getImageSize(strImage,200,"both","both","height") 266,200 100,200 500,200 125,200 Resizes the image so that the height is 200 pixels.
    getImageSize(strImage,200,"both","both","width") 200,150 100,200 200,80 125,200 Resizes the image so that the width is 200 pixels.
    getImageSize(strImage,200,"both","both","both") 266,200 200,400 500,200 200,320 Resizes the image so that the shortest dimension is 200 pixels.
    getImageSize(strImage,200,"both","both","one") 200,150 100,200 200,80 125,200 Resizes the image so that the longest dimension is 200 pixels.
     
    getImageSize(strImage,200,"both","width","none") 200,150 50,100 200,80 150,240 Resizes the image width so that the width is 200 pixels, does not enlarge width.
    getImageSize(strImage,200,"both","width","height") 200,150 50,100 200,80 150,240 Resizes the image width so that the width is 200 pixels, does not enlarge width.
    getImageSize(strImage,200,"both","width","width") 200,150 200,400 200,80 200,320 Resizes the image width so that the width is 200 pixels, only enlarges width.
    getImageSize(strImage,200,"both","width","both") 200,150 200,400 200,80 200,320 Resizes the image width so that the width is 200 pixels, only enlarges width.
    getImageSize(strImage,200,"both","width","one") 200,150 200,400 200,80 200,320 Resizes the image width so that the width is 200 pixels, only enlarges width.
     
    getImageSize(strImage,200,"both","height","none") 266,200 50,100 300,120 125,200 Resizes the image height so that the height is 200 pixels, does not enlarge height.
    getImageSize(strImage,200,"both","height","height") 266,200 100,200 500,200 125,200 Resizes the image height so that the height is 200 pixels, only enlarges height.
    getImageSize(strImage,200,"both","height","width") 266,200 50,100 300,120 125,200 Resizes the image height so that the height is 200 pixels, does not enlarge height.
    getImageSize(strImage,200,"both","height","both") 640,480 100,200 500,200 150,240 Resizes the image height so that the height is 200 pixels, only enlarges height.
    getImageSize(strImage,200,"both","height","one") 266,200 50,100 300,120 150,240 Resizes the image height so that the height is 200 pixels, only enlarges height.
     
    Download getImageSize() function:
    
    <!--- ============ GET IMAGE SIZE ============ --->
    <CFFUNCTION name="GetImageSize" returnType="any" output="Yes" hint="This function will return information about an image passed to it depending on the arguments passed.">
    	<CFARGUMENT name="ImageUsed" type="string" required="Yes">
    	<CFARGUMENT name="MaxSize" type="numeric" required="Yes">
    	<CFARGUMENT name="ReturnValue" type="string" required="No" default="width"> <!--- both, height, width --->
    	<CFARGUMENT name="OnlyDimension" type="string" required="No" default="both"> <!--- both, height, width --->
    	<CFARGUMENT name="Enlarge" type="string" required="No" default="both"> <!--- none, both, one, height, width --->
    	<!--- For images in another folder or another disk, prepend this path --->
    	<CFARGUMENT name="PrependPath" type="string" required="No" default="">
    
    <!---
    	###################################################
    	## Author: George Jaros                          ##
    	## Script Name: ColdFusion GetImageSize Function ##
    	## Copyright 2006 George Jaros & Web 2 Market    ##
    	## www.georgejaros.com  www.web2market.com       ##
    	## This code may be replicated as long as        ##
    	## this header statement is included.  The       ##
    	## Instructions below may be removed.            ##
    	## History:                                      ##
    	##  08.22.2006                                   ##
    	##  Add optional param "PrependPath"             ##
    	##   {string, default ""}                        ##
    	##   For images in another folder, another disk, ##
    	##   prepend this path. (by N. Sepsenwol)        ##
    	###################################################
    
    	This function will return information about an image passed to it depending on the arguments passed.
    	The function will return the appropriate dimensions of the image resized to the value set in the MaxSize field.
    	
    	Returns "Width,Height" as comma delimited list of integers, Width as integer, or Height as integer
    		
    		ImageUsed - This is the path to the image being tested.
    		MaxSize - This is the maximum size that the image should be in the designated dimension.
    		ReturnValue - This is the value that you want returned, either the width (default), height, or both in a comma delimited list.
    		OnlyDimension - Setting this to height or width will only resize that dimension.  Default is both.
    		Enlarge - If the dimensions are less than the MaxSize argument, should the image be enlarged?  Default is Both.
    			none - Neither dimension should be enlarged.
    			both - Both dimensions should be enlarged.  The image will have it's shortest dimension = MaxSize
    			one - Only one dimension will be enlarged, whichever is larger.  This ensures that the largest dimension = MaxSize
    			height - Only the height will be enlarged.  This causes the image to have the height = MaxSize
    			width - Only the width will be enlarged.  This causes the image to have the width = MaxSize
    		PrependPath - For images in another folder or another disk, prepend this path.
    	
    	Examples:
    	
    	Original Image Size: 
    	ImgA = 640 wide x 480 high 
    	ImgB = 50 wide x 100 high 
    	ImgC = 300 wide x 120 high 
    	ImgD = 150 wide x 240 high 
     
       FUNCTION                                               |  Img A    |  Img B    |  Img C    |  Img D    | COMMENTS  
       ImageUsed,MaxSize,ReturnValue,OnlyDimension,Enlarge    |   w,h     |   w,h     |   w,h     |   w,h     | Returns "Width,Height" 
       ------------------------------------------------------------------------------------------------------------------------------------------ ---------- ------ --- -- - -  -   -    -     -      -       -        -
       getImageSize(strImage,0,"both")                        | 640,480   |  50,100   | 300,120   | 150,240   | Returns the actual dimensions of the image. 
                                                              |           |           |           |           |
       getImageSize(strImage,200,"both","both","none")        | 200,150   |  50,100   | 200,80    | 125,200   | Resizes the image so that the longest dimension is 200 pixels, but does not enlarge the image. 
       getImageSize(strImage,200,"both","both","height")      | 266,200   | 100,200   | 500,200   | 125,200   | Resizes the image so that the height is 200 pixels. 
       getImageSize(strImage,200,"both","both","width")       | 200,150   | 100,200   | 200,80    | 125,200   | Resizes the image so that the width is 200 pixels. 
       getImageSize(strImage,200,"both","both","both")        | 266,200   | 200,400   | 500,200   | 200,320   | Resizes the image so that the shortest dimension is 200 pixels. 
       getImageSize(strImage,200,"both","both","one")         | 200,150   | 100,200   | 200,80    | 125,200   | Resizes the image so that the longest dimension is 200 pixels. 
                                                              |           |           |           |           |
       getImageSize(strImage,200,"both","width","none")       | 200,150   |  50,100   | 200,80    | 150,240   | Resizes the image width so that the width is 200 pixels, does not enlarge width. 
       getImageSize(strImage,200,"both","width","height")     | 200,150   |  50,100   | 200,80    | 150,240   | Resizes the image width so that the width is 200 pixels, does not enlarge width. 
       getImageSize(strImage,200,"both","width","width")      | 200,150   | 200,400   | 200,80    | 200,320   | Resizes the image width so that the width is 200 pixels, only enlarges width. 
       getImageSize(strImage,200,"both","width","both")       | 200,150   | 200,400   | 200,80    | 200,320   | Resizes the image width so that the width is 200 pixels, only enlarges width. 
       getImageSize(strImage,200,"both","width","one")        | 200,150   | 200,400   | 200,80    | 200,320   | Resizes the image width so that the width is 200 pixels, only enlarges width. 
                                                              |           |           |           |           |
       getImageSize(strImage,200,"both","height","none")      | 266,200   |  50,100   | 300,120   | 125,200   | Resizes the image height so that the height is 200 pixels, does not enlarge height. 
       getImageSize(strImage,200,"both","height","height")    | 266,200   | 100,200   | 500,200   | 125,200   | Resizes the image height so that the height is 200 pixels, only enlarges height. 
       getImageSize(strImage,200,"both","height","width")     | 266,200   |  50,100   | 300,120   | 125,200   | Resizes the image height so that the height is 200 pixels, does not enlarge height. 
       getImageSize(strImage,200,"both","height","both")      | 640,480   | 100,200   | 500,200   | 150,240   | Resizes the image height so that the height is 200 pixels, only enlarges height. 
       getImageSize(strImage,200,"both","height","one")       | 266,200   |  50,100   | 300,120   | 150,240   | Resizes the image height so that the height is 200 pixels, only enlarges height. 
    --->
    
    	<cfobject type="JAVA" action="Create" name="tk" class="java.awt.Toolkit">
    	<cfobject type="JAVA" action="Create" name="img" class="java.awt.Image">
    	<cfif PrependPath NEQ "">
    		<!--- Prepend imageUsed param with a hard-coded path; assumes no final "\" --->
    		<cfset ImageDirPath = PrependPath>
    	<cfelse>
    		<!--- Assume the relative path --->
    		<CFSET ImageDirPath = CGI.Path_Translated>
    		<CFSET ImageDirPath = ListDeleteAt(ImageDirPath,ListLen(ImageDirPath,"\"),"\")>
    	</cfif>
    	<CFSET ImagePath = Replace(ImageUsed,"/","\","ALL")>
    
    	<cfscript>
    	img = tk.getDefaultToolkit().getImage("#ImageDirPath#\#ImagePath#");
    	width = img.getWidth();
    	height = img.getHeight();
    	</cfscript>
    	<CFIF MaxSize GT 0>
    		<CFIF Lcase(OnlyDimension) EQ "both" OR Lcase(OnlyDimension) EQ "width">
    			<CFIF Lcase(Enlarge) EQ "both" OR Lcase(Enlarge) EQ "width" OR Lcase(Enlarge) EQ "one">
    				<CFIF width NEQ MaxSize>
    					<CFSET numerator = MaxSize/width>
    					<CFSET width = MaxSize>
    					<CFSET height = numerator * height>
    				</CFIF>
    			<CFELSE>
    				<CFIF width GT MaxSize>
    					<CFSET numerator = MaxSize/width>
    					<CFSET width = MaxSize>
    					<CFSET height = numerator * height>
    				</CFIF>
    			</CFIF>
    		</CFIF>
    		<CFIF Lcase(OnlyDimension) EQ "both" OR Lcase(OnlyDimension) EQ "height">
    			<CFIF Lcase(Enlarge) EQ "both">
    				<CFIF height LT MaxSize>
    					<CFSET numerator = MaxSize/height>
    					<CFSET height = MaxSize>
    					<CFSET width = numerator * width>
    				</CFIF>
    			<CFELSEIF Lcase(Enlarge) EQ "height">
    				<CFIF height NEQ MaxSize>
    					<CFSET numerator = MaxSize/height>
    					<CFSET height = MaxSize>
    					<CFSET width = numerator * width>
    				</CFIF>
    			<CFELSEIF Lcase(Enlarge) EQ "one">
    				<CFIF height GTE MaxSize AND width GTE MaxSize>
    					<CFSET numerator = MaxSize/height>
    					<CFSET height = MaxSize>
    					<CFSET width = numerator * width>
    				</CFIF>
    			<CFELSE>
    				<CFIF height GT MaxSize>
    					<CFSET numerator = MaxSize/height>
    					<CFSET height = MaxSize>
    					<CFSET width = numerator * width>
    				</CFIF>
    			</CFIF>
    		</CFIF>
    	</CFIF>
    	<CFSET img = "">
    	<CFSET tk = "">
    	<CFIF Lcase(ReturnValue) EQ "both">
    		<CFRETURN "#Int(width)#,#Int(height)#">
    	<CFELSEIF Lcase(ReturnValue) EQ "height">
    		<CFRETURN Int(height)>
    	<CFELSE>
    		<CFRETURN Int(width)>
    	</CFIF>
    </CFFUNCTION>
    <!--- ============ END GET IMAGE SIZE ============ --->
    
    

    ImgA:
    ImgB:
    ImgC:
    ImgD:

    eXTReMe Tracker