CFLib.org – Common Function Library Project

bhImgInfo(imgfile)

Last updated September 16, 2007
Download UDF

author

Bobby Hartsfield                                  Bobby Hartsfield

Version: 1 | Requires: ColdFusion MX | 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:

<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>

Search CFLib.org


Latest Additions

Raymond Compton Raymond Compton added
structBlend
19 day(s) ago

Duncan Duncan added
IsZIPUK
19 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
25 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson