Quick and Dirty Way to get Image Dimensions

By | | ColdFusion

…posted by davidjmedlock:

img = tk.getDefaultToolkit().getImage("C:\image.jpg"); width = img.getWidth(); height = img.getHeight(); #width#
#height#

I’m by no means a master of all things Java, but this is an easy way to grab the height and width of an image. I haven’t tried it with GIF’s just yet, but I think it’ll work… Enjoy!

Written By:

davidjmedlock

Website
>> More Posts By davidjmedlock

 

{ 11 comments }

dmoola@gmail.com June 27, 2007 at 12:38 pm

i always get -1 for both height and width…hrmph!

Joe May 7, 2006 at 2:29 am

I am also trying to make this work on Linux with no luck.

Steveroot, have you found a solution on Linux.

I`m looking for a way to determine a photo`s width and height so if any one has any suggestions it would be very much apreciated.

steveroot April 2, 2005 at 7:53 am

Does anyone have this working on Linux?

jrockfl November 9, 2004 at 11:32 am

Here is an example that uses it with online images.



SELECT image
FROM table







img = tk.getDefaultToolkit().getImage(“C:\www\www.yourdomain.com\images\#image#”);
width = img.getWidth();
height = img.getHeight();


#image#

Pilar October 20, 2004 at 5:17 pm

How can I use this script with online images. Ex. http://www.images.com/image.jpg ?

sam October 18, 2004 at 1:00 pm

anyway of doing this with SWFs?

Tom Tedeschi August 25, 2004 at 10:34 am

Looks great, but I get this error… any thoughts?

Element GETDEFAULTTOOLKIT is undefined in TK.
The error occurred in D:\Inetpub\flatfishdesign\ii\asis\imageSize.cfm: line 4

2 :
3 :
4 : img = tk.getDefaultToolkit.getImage(“./images/espn.gif”);
5 : width = img.getWidth();
6 : height = img.getHeight();

lnxuser July 30, 2004 at 10:19 am

Wow! This is great! Thanks for posting this.

tonyB July 7, 2004 at 7:30 pm

A W E S O M E ! …thanks, I needed this!

jonese May 18, 2004 at 1:47 pm

try removing the () after getDefaultToolkit so it becomes img = tk.getDefaultToolkit.getImage(“C:\image.jpg”);

QCWmstr May 10, 2004 at 7:17 pm

I tried using this script and CF didn’t like the second period on the first script line – the one after getDefaultToolkit()

Am I doing something wrong?

Comments on this entry are closed.