Solved

How do i get the image dimension from the image URL? -

Posted on 2007-11-21
1
706 Views
Last Modified: 2013-12-25
Hi There,
Any one here know how to get the image width and height from the URL. That is i need the image width and height when it loading in the browser. So i can adjust the image size with respect to the  original dimension when it display on the browser . any help would be greatly apppriciated
0
Comment
Question by:palanee83
1 Comment
 
LVL 18

Accepted Solution

by:
Morcalavin earned 20 total points
ID: 20328650
You can't get the width and height of the image just from the url(without some type of server side scripting).  The image would have to be loaded somewhere before you can tell how big it is.

However, you can load it in an absolute, hidden div and use offsetWidth/height to get the size of it.  This  is a quick example of how to get the image size, without actually showing the image.  You can add javascript to resize the image later or whatever.(tonberry.gif is a file of mine that is 339x300)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
 
</script>
<style type="text/css">
	#imageloader
	{
		visibility: hidden;
		position:absolute;
	}
</style>
<title>Untitled Document</title>
</head>
 
<body>
<div><input type="button" value="Get Image Size" onclick="alert(document.getElementById('image').offsetWidth + 'x' + document.getElementById('image').offsetHeight) " /></div>
<div id="imageloader"><img id="image" src="tonberry.gif"></div>
</body>
</html>

Open in new window

0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question