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>

About This Tutorial
Author: Russ Michaels
Skill Level: Intermediate 
 
 
 
Platforms Tested: CFMX
Total Views: 29,242
Submission Date: March 31, 2003
Last Update Date: June 05, 2009
All Tutorials By This Autor: 1
Discuss This Tutorial
  • 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.

  • I have tried with the full directory path, still it returns -1

  • If you replace #file.serverdirectory# with the full directory path, then the code works just fine!

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

  • The script seems to return "-1" for both width and height... ami I missing something?

Advertisement

Sponsored By...
Powered By...