Get image dimensions

Here is a quick and dirty (and easy) way to get the width and height of an image. It should work for both JPG and GIF files:

<cfobject type="JAVA" action="Create" name="tk" 
          class="java.awt.Toolkit">
</cfobject>
<cfobject type="JAVA" action="Create" name="img" 
          class="java.awt.Image">
</cfobject>
<cfscript>
img = tk.getDefaultToolkit().getImage("c:\img.gif");
width = img.getWidth();
height = img.getHeight();
</cfscript>
<cfoutput>#width#<br />#height#</cfoutput>

That’s the beauty of ColdFusion, you have all of the Java language available to you right out of the box. ColdFusion is after all a Java application behind the scene.

source


Tagged , | Comments Closed | Trackbacks Closed