Server Time:
Sunday May 11 2008 08:10 PM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Calculating imag size
by: Russ Michaels
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

After uploading your image, use the following code to calculate it's size.

<cfscript>
   imageObj = createObject("java", "java.awt.Toolkit");
   imagetools = imageObj.getDefaultToolkit();
   objImage = imagetools.getImage("#file.serverdirectory##file.Serverfile#");
   width = objImage.getWidth();
   height = objImage.getHeight();
</cfscript>

Then use the values how you wish, to store in a database, deny an upload according to sizes etc. The following just outputs the values for info.

<cfoutput>
  width: #width#<br>
  height: #height#
</cfoutput>


Date added: Mon. March 31, 2003
Posted by: Russ Michaels | Views: 10661 | Tested Platforms: CFMX | Difficulty: Intermediate
Categories Listed: Uploading

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

This author's other tutorials:
Creating Secure instances with CFMX 7 Multi Server
How to create secure islocated JRUN instances using ColdFusion MX 7 multi server. This allows each instance to be securely isloated from others to get arounnd the JAVA security issues that cannot be cured with sandboxing. - Date added: Mon. July 10, 2006
Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Comments on this tutorial
Read previous comments on this particular tutorial
Returns -1
The script seems to return "-1" for both width and height... ami I missing something?
Posted by: Tom Tedeschi
Posted on: 08/25/2004 08:56 AM
return -1
You would get -1 if there is nothing to evaluate, i.e the image has not been uploaded or it was a zero byte file or you have specified an invalid path to the image.
Posted by: russ Michaels
Posted on: 08/25/2004 09:25 AM
Returns -1
If you replace #file.serverdirectory# with the full directory path, then the code works just fine!
Posted by: Paresh Dawda
Posted on: 09/20/2004 03:48 PM

I have tried with the full directory path, still it returns -1
Posted by: bigculkin
Posted on: 09/21/2004 02:11 AM
-1
Find:

objImage = imagetools.getImage("#file.serverdirectory##file.Serverfile#");

Replace with;

objImage = imagetools.getImage("#cffile.serverdirectory#\#cffile.Serverfile#");

It was returning -1 because the author forgot to add a backwards slash. And, file should be cffile.
Posted by: Matt
Posted on: 08/24/2005 01:57 PM
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
Daily Razor - ColdFusion Hosting

You are 1 of 712 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb