I need to read the with of a gif or a jpg, before the page has finished loaded. This is because I have to set the width of a floating div to get the layout right.
/Smirre
Printable View
I need to read the with of a gif or a jpg, before the page has finished loaded. This is because I have to set the width of a floating div to get the layout right.
/Smirre
I'm not sure if this will work but its worth a try...
<script language="javascript" type="text/javascript">
document.write '<img src="image.jpg">';
// code to get width
</script>
...and put it in the head of the document as this is loaded before the rest of the page
Can I read the image as an object and then read the width of the object???
/Smirre
This doesn't work?
http://www.vbforums.com/showthread.php?threadid=153714
Yes, I got it to work, but I have a image and a image text. The Image is inside a div, the text is in another div, and the two divs is inside the div that floats.
But witout setting the size, the div took up all the width of the page. And setting the width with % and pixels to 1 made the div with the text act funny in netscape.
Have found a solution, reading the image file byte wise with asp and setting the width with the style tag.
The image width cant be read with javascript on a page load. Images are not loaded until the code on the page has loaded, this is in netscape only...
/Smirre
Wow... this is entirely too complicated.
Remember that CSS width is only the width of the content, and excludes border, padding, and margin. Also, I believe images fall under the replaced content rules.
Please, can you post the code to do this?Quote:
Originally posted by Smirre
Yes, I got it to work, but I have a image and a image text. The Image is inside a div, the text is in another div, and the two divs is inside the div that floats.
But witout setting the size, the div took up all the width of the page. And setting the width with % and pixels to 1 made the div with the text act funny in netscape.
Have found a solution, reading the image file byte wise with asp and setting the width with the style tag.
The image width cant be read with javascript on a page load. Images are not loaded until the code on the page has loaded, this is in netscape only...
/Smirre
Maybe this link can be of help. Is this what you used?
http://www.4guysfromrolla.com/webtec...imgsz.asp.html
From the link above, the code that could be used:
VB Code:
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: '::: ::: '::: This function does most of the real work. It will attempt ::: '::: to read any file, regardless of the extension, and will ::: '::: identify if it is a graphical image. ::: '::: ::: '::: Passed: ::: '::: flnm => Filespec of file to read ::: '::: width => width of image ::: '::: height => height of image ::: '::: depth => color depth (in number of colors) ::: '::: strImageType=> type of image (e.g. GIF, BMP, etc.) ::: '::: ::: '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: function gfxSpex(flnm, width, height, depth, strImageType) dim strPNG dim strGIF dim strBMP dim strType strType = "" strImageType = "(unknown)" gfxSpex = False strPNG = chr(137) & chr(80) & chr(78) strGIF = "GIF" strBMP = chr(66) & chr(77) strType = GetBytes(flnm, 0, 3) if strType = strGIF then ' is GIF strImageType = "GIF" Width = lngConvert(GetBytes(flnm, 7, 2)) Height = lngConvert(GetBytes(flnm, 9, 2)) Depth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1) gfxSpex = True elseif left(strType, 2) = strBMP then ' is BMP strImageType = "BMP" Width = lngConvert(GetBytes(flnm, 19, 2)) Height = lngConvert(GetBytes(flnm, 23, 2)) Depth = 2 ^ (asc(GetBytes(flnm, 29, 1))) gfxSpex = True elseif strType = strPNG then ' Is PNG strImageType = "PNG" Width = lngConvert2(GetBytes(flnm, 19, 2)) Height = lngConvert2(GetBytes(flnm, 23, 2)) Depth = getBytes(flnm, 25, 2) select case asc(right(Depth,1)) case 0 Depth = 2 ^ (asc(left(Depth, 1))) gfxSpex = True case 2 Depth = 2 ^ (asc(left(Depth, 1)) * 3) gfxSpex = True case 3 Depth = 2 ^ (asc(left(Depth, 1))) '8 gfxSpex = True case 4 Depth = 2 ^ (asc(left(Depth, 1)) * 2) gfxSpex = True case 6 Depth = 2 ^ (asc(left(Depth, 1)) * 4) gfxSpex = True case else Depth = -1 end select else strBuff = GetBytes(flnm, 0, -1) ' Get all bytes from file lngSize = len(strBuff) flgFound = 0 strTarget = chr(255) & chr(216) & chr(255) flgFound = instr(strBuff, strTarget) if flgFound = 0 then exit function end if strImageType = "JPG" lngPos = flgFound + 2 ExitLoop = false do while ExitLoop = False and lngPos < lngSize do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize lngPos = lngPos + 1 loop if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2)) lngPos = lngPos + lngMarkerSize + 1 else ExitLoop = True end if loop ' if ExitLoop = False then Width = -1 Height = -1 Depth = -1 else Height = lngConvert2(mid(strBuff, lngPos + 4, 2)) Width = lngConvert2(mid(strBuff, lngPos + 6, 2)) Depth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8) gfxSpex = True end if end if end function
why dont u put the image in a layer with no width specifacation. then the layer will be exactly same width. Make this layer invisible and then just use the layer width as the image width
Because when you change the width of the layer you must also change the height of the image... In order to calculate the resizing factor, you need those properties.
In my case, I do not want an image to be uploaded to my site with dimensions larger than a variable integer. Also, when I resize, I want either the width or the height to me less or equal to a variable size. Therefore I need to know the properties and calculate the resizing factor...