Wow... that looks eerily familiar to this...
/*
* Returns image height, width and file size (kb, kB, mB)
*
* @param imgfile Absolute path to a valid image file
(Required)
* @param appname Application name. (Required)
* @return Returns a struct.
* @author Bobby Hartsfield ([EMAIL PROTECTED])
* @version 3
* @created May 8, 2006
*/
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;
}
:-)
Anyway... If you don't need to change it or lose it... just use a persistent
scope for it. Then you can pass it around to whatever you want.
function init_image()
{
application.imgObj = CreateObject("java","java.awt.image.BufferedImage");
application.imgRdr = CreateObject("java","javax.imageio.ImageIO");
}
function set_size(image_name){
f =
CreateObject("java","java.net.URL").init('http://www.sph.umd.edu/images/care
erexpo.jpg');
imgObj = application.imgRdr.read(f);
imgObj.imageWidth = imgObj.getWidth();
imgObj.imageHeight = imgObj.getHeight();
return imgObj;
}
..:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
http://cf4em.com
-----Original Message-----
From: Robert Harrison [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 14, 2008 10:37 AM
To: CF-Talk
Subject: RE: image size setup
> Recently, someone has posted how to check image sizes using java in CF.
> This was not posted by me, but it was in response to my query. Works
great. My thanks to the person who first posted it.
<!--- function to get the properties of the image file --->
<cfscript>
function get_imageinfo(imgfile){
jFileIn = createObject("java","java.io.File").init(imgfile);
ImageInfo = StructNew();
ImageObject =
createObject("java","javax.imageio.ImageIO").read(jFileIn);
imageFile = CreateObject("java", "java.io.File");
imageFile.init(imgfile);
sizeb = imageFile.length();
sizekb = numberformat(sizeb / 1024, "999999999.99");
sizemb = numberformat(sizekb / 1024, "99999999.99");
get_imginfo = StructNew();
get_imginfo.ImgWidth = ImageObject.getWidth();
get_imginfo.ImgHeight = ImageObject.getHeight();
get_imginfo.SizeKB = sizekb;
get_imginfo.SizeMB = sizemb;
get_imginfo.ImageFormat = ListLast(ListLast(imgfile, "\"), ".");
}
</cfscript>
<cfset tmp = get_imageinfo("MYPATH\MYFILENAME") /> <!--- this is
the image file to get --->
<cfset width=#get_imginfo.ImgWidth#> <!--- this is
the resulting image width --->
<cfset height=#get_imginfo.ImgHeight#> <!--- this is
the resulting image height --->
<!--- now define what to test width and height against and what to
do --->
<cfif width gt MYMAXWIDTH or height gt MYMAXHEIGHT>
File To Large
<cfelse>
File OK
</cfif>
Robert B. Harrison
Director of Interactive services
Austin & Williams
125 Kennedy Drive, Suite 100 Hauppauge NY 11788
T : 631.231.6600 Ext. 119
F : 631.434.7022
www.austin-williams.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:305233
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4