CFLib.org – Common Function Library Project

bhImgInfo(imgfile)

Last updated September 16, 2007

author

Bobby Hartsfield

Version: 1 | Requires: CF6 | Library: UtilityLib

Description:
javax.imageio.ImageIO based image function to gather and return basic info about an image such as Height, width, and file Size (B, KB and MB)

Return Values:
Returns a struct.

Example:

<cfset img = bhImgInfo("c:\inetpub\wwwroot\image.jpg") />
<cfdump var="#img#" />

Parameters:

Name Description Required
imgfile Absolute path to image file. Yes

Full UDF Source:

/**
 * Image function to return Height, Width and file size.
 * 
 * @param imgfile 	 Absolute path to image file. (Required)
 * @return Returns a struct. 
 * @author Bobby Hartsfield (bobby@acoderslife.com) 
 * @version 1, September 16, 2007 
 */
function bhimginfo(imgfile) {
	var jFileIn = createObject("java","java.io.File").init(imgfile);
	var ImageObject = createObject("java","javax.imageio.ImageIO").read(jFileIn);
	var ImageInfo = StructNew();
	
	var imageFile = CreateObject("java", "java.io.File").init(imgfile); 
	var sizeb = imageFile.length();
	var sizekb = numberformat(sizeb / 1024, "999999999.99");
	var sizemb = numberformat(sizekb / 1024, "99999999.99");
	var bhImageInfo = StructNew();

	bhImageInfo.ImgWidth = ImageObject.getWidth();
	bhImageInfo.ImgHeight = ImageObject.getHeight();
	bhImageInfo.SizeB = sizeb;
	bhImageInfo.SizeKB = sizekb;
	bhImageInfo.SizeMB = sizemb;
	
	return bhImageInfo;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson