• 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
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

how to get image widt h and height?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone,

i am using javascript and php in my web application.
before i display images, i would like to get their width and height. i used the getimagesize() function of php, but there are time when the width and height returned are blanks. i dont know how and i dont know why but there are really times like this. because of this, i started to search for a workaround when this scenario happens.

i placed an onload function in my img tag. in that function i used this.width and this.height to get the size. but then, they returned zeroes. i dont know what to do now.

can anybody please help me? how do i get the image width and height?

thanks a lot.
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this.offsetWidth and this.offsetHeight.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is an Example :



its not related with your requirement but it gives you an idea..
[ August 21, 2007: Message edited by: Saif uddin ]
 
f jimenez
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello guys,

i am really not interested in getting the width and height of the image per se. but im interested in getting their height and width on or after they load. i have to do this to display the image correctly. if the image width is bigger than that of the height, the image is to be displayed with a width of 100. else, its height will be 90. so this has to be done before the image is displayed. i have placed a function which gets the width and height in the onload of the image object, but unfortunately it returns a zero. i have no idea why but it really does this.

thanks a lot.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please have a look at http://truetalkdev.blogspot.com/2007/07/get-image-size-after-image-is-fully.html .
 
f jimenez
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dan Drillich:
Please have a look at http://truetalkdev.blogspot.com/2007/07/get-image-size-after-image-is-fully.html .



i have already seen this but it doesn't work as well... i have tried it with my pc and its fine. but when i tried to use it in the real server, it wont work...
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by f jimenez:

i have tried it with my pc and its fine. but when i tried to use it in the real server, it wont work...


confused, as this code is runs only on client side.

are you getting any error?
 
f jimenez
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Saif uddin:

confused, as this code is runs only on client side.

are you getting any error?



im not getting any error... what i meant by server is the computer where this codes will be deployed... of course, javascript runs client side.
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic