CFLib.org – Common Function Library Project

bhImgInfo(imgfile)

Last updated September 16, 2007

Version: 1 | Requires: ColdFusion MX | Library: UtilityLib

 
Rated 7 time(s). Average Rating: 4.9

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:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
15 day(s) ago

James Sleeman James Sleeman added
quickSort
25 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
28 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson