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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Img Width and Height

Status
Not open for further replies.

Silvano

Programmer
Jul 16, 2001
386
US
This is the script I am using to get uploaded image width and height; it is working fine if tested on separate cfm file;
when returned in application environment, it will return imgWidth and imgHeight as 28 and 30, respectively; (28 by 30 are dimensions of the "bad link" image);
the weird part is that image link is NOT bad; the script is executing fine, and I can see the image, but for some reason script will not read the image width and height properly
one more thing: if I click reload in the browser (somethimes once, somethimes 2-3 times), the script will "pick-up" correct image width and height and it will display 125 by 80 or whatever image width and height is

I understand that is very difficult to explain behavior such as this, especially if you don't have the whole thing in front of you, so I am just asking: have anyone had experience similar to this?

If so, I would appriciate just about any imput that will help me understand behavior such as this.

Thanks


<cfif uplInfo NEQ &quot;&quot;>
<cfset file = Replace(ListGetAt(uplInfo, &quot;7&quot;), &quot; &quot;, &quot;&quot;, &quot;all&quot;)>

<div id=&quot;hiddenImage&quot; style=&quot;position:absolute;&quot;>
<img src=&quot;storage/<cfoutput>#file#</cfoutput>&quot; name=&quot;img1&quot;>
</div>

<script language=&quot;JavaScript&quot;>
if (parseInt(navigator.appVersion) >= 4) {
if (navigator.appName == &quot;Netscape&quot;) {isNav = true;}
else {isNav = false;}
}

if (!isNav) {
img = document.all('hiddenImage');
} else {
img = document.layers['hiddenImage'];
}
imgWidth = img.document.images['img1'].width;
imgHeight = img.document.images['img1'].height;

</script>
<cfelse>
<script language=&quot;JavaScript&quot;>
var imgWidth = 0;
var imgHeight = 0;
</script>
</cfif>
 
Hi,

This is just an idea, but I think that an image starts out as a 'bad link' and is then filled with the correct image.

Meaning that if the image can't be loaded (for whatever reason), the 'bad link' will already be in place.

So, if you check the width and height of the image too soon, you will get the dimensions of this 'bad link' image which is active during loading. If so, this would also explain why the scripts gets the right dimensions after a few reloads. Because the image is already in the cache, it will be loaded much faster meaning that the script can be executed correctly.

The sollution to this might be using a function which is called at onload:

Code:
function getDim() {
	if (parseInt(navigator.appVersion) >= 4) {
		if (navigator.appName == &quot;Netscape&quot;) {isNav = true;}
		else {isNav = false;}
	}
	
	if (!isNav) {
		img = document.all('hiddenImage');
	} else {
		img = document.layers['hiddenImage'];
	}
	imgWidth = img.document.images['img1'].width;
	imgHeight = img.document.images['img1'].height;
}

onload=&quot;getDim()&quot;

This is just an idea, don't know if it would actually work ;-)

Hope it does.

Gtz,

Kristof
 
i've had problems in the past writing a JavaScript program that obtains both width and height and works in both IE and NS.

If you have access to use CFX dll tags, then there are 3 you could look into using:

CF_Img(v1.2) by S.Martin & P.Murphy
Used in place of <img src=...>, <CF_IMG> automatically fills in the width= and height= attributes of the IMG tag. n.b. CF_IMG takes the form of a custom tag and a .DLL

CFX_ImageInfo SE (Special Edition)
It returns ONLY the width, height and size of any of the following graphic file formats: TGA, GIF, JPG, PNG, BMP, PCX, TIFF, and PSD. Works with ColdFusion version 4.0.1 and up.

CFX_GIFGD by Jukka Manner
The CFX_GIFGD allows you read and manipulate GIF/JPG/PNG and BMP image. JPG, PNG and BMP formats are currently read-only formats, with the exception of conversion and resize actions.
- tleish
 
Thanks guys, the CFX_ImageInfoSE is exactly what I need...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top