Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Dimensions

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
Is there any way that I can read the dimensions of an image file. I need to get the height and width of the file, to for positioning purposes in DHTML. I really don't want to use a custom tag for this, if possible, as the site might be moving to another server @ an ISP soon, and they only support a couple of tags per site !

Any ideas ??
 
I don't think there will be any way to do this without a custom tag. The problem is that each image format such as .gif, .png, .jpg, etc.. has an entirely different layout as far as how pixels are stored and compressed. In order to find the dimensions of a .jpg for example, you have to know where in the data file this is stored and there are no built in CF functions that will do this (that I'm aware of). If you wanted to spend the time though, you could research the format of the images you need to do this with and possibly find how the information is stored. You could then use <cffile> to read in the contents of the image file into a variable and then parse through the data to find the dimensions. This is basically what they would do in a custom tag and would most likely be more efficient than in a script.

Sorry but I don't know of a simple way to do this without the use of a custom tag.
GJ
 
Thanks for the response, you've confirmed what i thought (feared !), if i get a spare monment/month I'll have a think about writing a script to do it

Cheers
 
You want this info for use in DHTML, so I suggest handling it all in Javascript. The biggest problem is probably that Netscape 4 doesn't let you change the size of an image object once it's defined (IE does). So I suggest your CF page should generate Javascript to.
* read the image into a work variable, e.g.
var X = new Image;
X.src = #imagefilename#;
* get the height and width of the image, and calculate the desired height and width if different.
* use document.writeln to write a DIV / LAYER (depending on the browser) and IMG of the desired sizes and then assign the preloaded image (X above) to the new IMG.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top