MrAdam Posted June 11, 2006 Share Posted June 11, 2006 hiya people, is it possibile in javascirpt to return the width and height of a given image... (not meaning the width="" and height="" attributes), if so... how? Thanks. Link to comment Share on other sites More sharing options...
scott100 Posted June 11, 2006 Share Posted June 11, 2006 hiya people, is it possibile in javascirpt to return the width and height of a given image... (not meaning the width="" and height="" attributes), if so... how? Thanks.<{POST_SNAPBACK}> Yes, just use .height and .width after the picture object.<html><head><script>function check(pic){alert("width: "+pic.width+"px");alert("height: "+pic.height+"px");}</script></head><body><img src="http://www.google.co.uk/logos/worldcup06_uk.gif" onclick="check(this)" /></body></html> Is that what you need? Link to comment Share on other sites More sharing options...
MrAdam Posted June 11, 2006 Author Share Posted June 11, 2006 thankyou Link to comment Share on other sites More sharing options...
katia Posted June 16, 2006 Share Posted June 16, 2006 Yes, just use .height and .width after the picture object.<html><head><script>function check(pic){alert("width: "+pic.width+"px");alert("height: "+pic.height+"px");}</script></head><body><img src="http://www.google.co.uk/logos/worldcup06_uk.gif" onclick="check(this)" /></body></html> Is that what you need? <{POST_SNAPBACK}> If the picture is on your server, how does it have to be the picture path? Because if the src is like this: "../Img/1.jpg" , pic.width and pic.heigth will return undefined. Link to comment Share on other sites More sharing options...
scott100 Posted June 16, 2006 Share Posted June 16, 2006 If the picture is on your server, how does it have to be the picture path? Because if the src is like this: "../Img/1.jpg" , pic.width and pic.heigth will return undefined.I'm not sure what you mean If you can access a picture by its path eg http://www.mysite.com/images/pic.jpgthen you can access it's dimensions. Link to comment Share on other sites More sharing options...
katia Posted June 16, 2006 Share Posted June 16, 2006 I'm not sure what you mean If you can access a picture by its path eg http://www.mysite.com/images/pic.jpgthen you can access it's dimensions.<{POST_SNAPBACK}> For now, my pc is my server, so should I use: "http://localhost/Img/1.jpg" as my path? Link to comment Share on other sites More sharing options...
scott100 Posted June 16, 2006 Share Posted June 16, 2006 For now, my pc is my server, so should I use: "http://localhost/Img/1.jpg" as my path?Yes that should work but if you upload your pages images to internet then other people wount see them."../Img/1.jpg" - that path should work if your page is in another folder at the same level as Img folder - like "http://localhost/Pages/mypage.php"It's all about asolute and relative file paths.so if you were on index.php then this should work - "Img/1.jpg" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now