• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get Image height and width

 
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get image size before I dynamically set it as background to a div object
so that, I can set height & width of the div accordingly.

I tried:





It worked fine with mozilla but not with IE.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read this.
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my html page I have one div tag with id 'somediv'.

On page load I want to set the div size, which is the size of the image.
To do this I created a new Image object & set the size of the div.
After setting the div size to the size of the image I set the image as background of the div object.
(Please see the above code.)

When I tried the code with Mozilla, the div get the size of the image.
But when I tried the same with Internet Explorer: The div is set to the size of the image.
But when I tried the same with different image sizes, in some cases the div did not take the size of the image.
This faulty behavior seldom happens, but I want it to completely resolve.

I am trying my code on Windows XP SP2, IE 6.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am guessing it has not loaded fully when you read the width and height. Try



Eric
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Eric... I am getting the desired results. Thank you again.
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The above mentioned problem was all because I named the jpg file 'bp.jpg'.

The problem is identified when tried with IE6.

When you name the file bp.jpg and try it with above mentioned code, and try to print
using . In IE6 it shows the wrong size.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The name of the image has nothing to do with the width and height.

If you get a value that is different, are you sure it is not using a cached version of the file?

Eric
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In IE6 I cleared all the cache: Internet Options - General tab (Delete Cookies, Delete Files & Clear History).

I closed the Browser & restart it and tried the same. It is strange to see that when
I changed the names of different file to 'bp', and tried the results were same, erroneous.

I don't know what is the reason! But may be it is similar to try to create folder naming 'con',
which is a reserved word and we can't create one with this name.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic