Calculating imag size

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>



All ColdFusion Tutorials By Author: Russ Michaels
  • Calculating imag size
    Ever wanetd to know the size of an uploaded image so that you can store in the database, or check if it falls into allowed sizes etc.
    Author: Russ Michaels
    Views: 10,995
    Posted Date: Monday, March 31, 2003
  • 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.
    Author: Russ Michaels
    Views: 4,304
    Posted Date: Monday, July 10, 2006