Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-11-21
1
Medium Priority
?
727 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
Morcalavin earned 60 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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The goal of the tutorial is to teach the user the full work flow of how to use flash media encoder to stream onto YouTube.
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.
Suggested Courses

598 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