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

"Real" image size ..

Status
Not open for further replies.

grega

Programmer
Feb 2, 2000
932
GB
Is there a way round this? Lets say I have a large image on a page, sized as a thumbnail, which I want to open in a new window at it's full size ...
Code:
<IMG SRC=&quot;myImage.jpg&quot; HEIGHT=&quot;90&quot; WIDTH=&quot;130&quot; onClick=&quot;openPic(this);&quot;>
The real height and width could be 300x500, but when I use the height and width properties of the image object passed to the openPic function, these return 90x130, i.e. what was set in the <IMG> tag.
Code:
function openPic(img)
{
  var iH=img.height; // I want these to return the actual size
  var iW=img.width;  // not the size set in the IMG tag
  // more code follows to open & size the window, etc.
  // but not relevant here
}
Is there any way to get at the real height and width of the image ... or do I need a separate thumbnail image?

Greg.
 
First of all, for bandwidth reasons, unless its a vector image, you should actually make the thumbnail pic. If you choose not to, a solution in IE is possible because of wonderful things called expando properties. This means you can give any object a property simply by saying

object.newproperty=somevalue;

you can, using this technique, put new attributes inside any element. so your image could have two new properties:

<img height=100 width=100 trueh=300 truew=300>

Not sure if there is something I'm missing about &quot;real height&quot; jared@aauser.com
 
Thanks Jared ... saved the day again! I'll experiment with these &quot;expando&quot; properties, but I think thumbnail is the way to go.

All I mean by &quot;real height&quot; is the height and width values returned by the object properties if I had not specified height & width in the <IMG> tag, i.e. the full size image.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top