CFLib.org – Common Function Library Project

bhImgInfo(imgfile)

Last updated September 17, 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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson