473,657 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

intrinsic size of an Image

Image.width returns the width of an image as it is displayed on a
browser page, which may be different from the image's intrinsic size
if the 'img' element had a 'width' attribute specified. Is there a
reliable way to find an image's intrinsic dimensions, irrespective of
the size specified in HTML?

Ari.

--
Elections only count as free and trials as fair if you can lose money
betting on the outcome.
Dec 4 '06 #1
13 3021
Ari Krupnik wrote :
Image.width returns the width of an image as it is displayed on a
browser page, which may be different from the image's intrinsic size
if the 'img' element had a 'width' attribute specified. Is there a
reliable way to find an image's intrinsic dimensions, irrespective of
the size specified in HTML?

Ari.
JS interacts with DOM to get those values. That's why, as you noticed, JS may
not retrieve the original picture size. But JS has no way, as I know, to work
with files (apart from Internet Explorer, the alien browser).
You may try to work with XMLHttpRequest, or find another way.
Or wait for someone who may contradict me about the JS working with files :)

--
Naixn
http://fma-fr.net
Dec 5 '06 #2
Ari Krupnik wrote:
Image.width returns the width of an image as it is displayed on a
browser page, which may be different from the image's intrinsic size
if the 'img' element had a 'width' attribute specified. Is there a
reliable way to find an image's intrinsic dimensions, irrespective of
the size specified in HTML?

Ari.
<img src="Someimage. jpg" ID='testImg' width=75 height=75>
<script language='javas cript'>
document.writel n(document.getE lementById('tes tImg').width+'< br>');
// returns 75 (the forced width of the IMG tag)
var test = new Image;
test.src = 'Someimage.jpg' ;
document.writel n(test.width); // returns real width of the picture.
</script>
Be aware that you'll need to test if the image is actually loaded before
testing width or you may get unpredictable results. This worked fine
when I tested it, but the image was in my browser's cache so do some
testing about how the various browsers return width when the image
hasn't fully (or started) loading yet.

---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA
Dec 5 '06 #3
pcx99 wrote :
Ari Krupnik wrote:
>Image.width returns the width of an image as it is displayed on a
browser page, which may be different from the image's intrinsic size
if the 'img' element had a 'width' attribute specified. Is there a
reliable way to find an image's intrinsic dimensions, irrespective of
the size specified in HTML?

Ari.

<img src="Someimage. jpg" ID='testImg' width=75 height=75>
<script language='javas cript'>
document.writel n(document.getE lementById('tes tImg').width+'< br>');
// returns 75 (the forced width of the IMG tag)
var test = new Image;
test.src = 'Someimage.jpg' ;
document.writel n(test.width); // returns real width of the picture.
</script>
Be aware that you'll need to test if the image is actually loaded before
testing width or you may get unpredictable results. This worked fine
when I tested it, but the image was in my browser's cache so do some
testing about how the various browsers return width when the image
hasn't fully (or started) loading yet.

---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA
Oh yeah, good idea !

The answer would then be to work after body unload and have something like :
<img src="someimage. jpg" id="testImg" />
<script language="javas cript">
function getImgHeight()
{
var test = new Image;
var test.src = document.getEle mentById('testI mg');
alert(test.heig ht);
}
</script>

Yep. Great from you pcx99 :)

--
Naixn
http://fma-fr.net
Dec 5 '06 #4
ASM
Ari Krupnik a écrit :
Image.width returns the width of an image as it is displayed on a
browser page, which may be different from the image's intrinsic size
if the 'img' element had a 'width' attribute specified. Is there a
reliable way to find an image's intrinsic dimensions, irrespective of
the size specified in HTML?
Only way I know is :

<html>
<script type="text/javascript">
function sizeImg(urlImg) {
var I = new Image()
I.onload = function() { alert('w = '+I.width+'\nh = '+I.height); }
I.src = urlImg
}
</script>
<img src="http://www.google.fr/intl/en_com/images/logo_plain.png"
width="100" alt="">
<a href="javascrip t:sizeImg(docum ent.images[0].src)">img's size</a>

<a
href="javascrip t:sizeImg('http ://eur.i1.yimg.com/eur.yimg.com/i/fr/se/sycf.gif')">
Yahoo! logo size</a>
</html>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 5 '06 #5
ASM
naixn a écrit :
The answer would then be to work after body unload and have something
like :
As you say that works after complete page loading and only with an image
already displayed or not in cache.

Could you try with :

<a href="#" onclick="var u = 'stephane.moria ux.'
u += 'perso.orange.f r/'; u += 'mac/images/carte.jpg'
getImgHeight('h ttp://'+u;return false;"try</a>

and tell me if that has worked with this 40ko image ?
<img src="someimage. jpg" id="testImg" />
<script language="javas cript">
function getImgHeight()
{
var test = new Image;
var test.src = document.getEle mentById('testI mg');
alert(test.heig ht);
}
</script>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 5 '06 #6
ASM
ASM a écrit :
>
Could you try with :
sorry there were some errors ...

<html>
<script type="text/javascript">
function sizeImg(urlImg) {
var I = new Image()
I.onload = function() { alert('w = '+I.width+'\nh = '+I.height); }
I.src = urlImg
}
function getImgHeight()
{
var test = new Image();
test.src = document.getEle mentById('testI mg');
alert(test.heig ht);
}
</script>
<p>
<a href="#" onclick="var u = 'stephane.moria ux.'
u += 'perso.orange.f r/'; u += 'mac/1520/images/carte.jpg';
getImgHeight('h ttp://'+u);return false;">first try</a>
<p>
<a href="#" onclick="var u = 'stephane.moria ux.'
u += 'perso.orange.f r/'; u += 'mac/1520/images/gestion_1.gif';
sizeImg('http://'+u);return false;">try by cache</a>
</html>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Contact : http://stephane.moriaux.perso.wanadoo.fr/contact
ASM = Aimable Stéphane Moriaux = Amateur Sasseur Merdouilles
Dec 5 '06 #7
ASM wrote:
ASM a écrit :
>>
Could you try with :

sorry there were some errors ...

<html>
<script type="text/javascript">
function sizeImg(urlImg) {
var I = new Image()
I.onload = function() { alert('w = '+I.width+'\nh = '+I.height); }
I.src = urlImg
}
function getImgHeight()
{
var test = new Image();
test.src = document.getEle mentById('testI mg');
alert(test.heig ht);
}
</script>
<p>
<a href="#" onclick="var u = 'stephane.moria ux.'
u += 'perso.orange.f r/'; u += 'mac/1520/images/carte.jpg';
getImgHeight('h ttp://'+u);return false;">first try</a>
<p>
<a href="#" onclick="var u = 'stephane.moria ux.'
u += 'perso.orange.f r/'; u += 'mac/1520/images/gestion_1.gif';
sizeImg('http://'+u);return false;">try by cache</a>
</html>


First try: 0
second try: 447w 339h
---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA
Dec 5 '06 #8
ASM <st************ *********@wanad oo.fr.invalidwr ote in news:4574daee$0
$5************@ news.orange.fr:
ASM a écrit :

<html>
<script type="text/javascript">
function sizeImg(urlImg) {
var I = new Image()
I.onload = function() { alert('w = '+I.width+'\nh = '+I.height); }
I.src = urlImg
}
function getImgHeight()
{
var test = new Image();
test.src = document.getEle mentById('testI mg');
alert(test.heig ht);
}
</script>
<p>
<a href="#" onclick="var u = 'stephane.moria ux.'
u += 'perso.orange.f r/'; u += 'mac/1520/images/carte.jpg';
getImgHeight('h ttp://'+u);return false;">first try</a>
<p>
<a href="#" onclick="var u = 'stephane.moria ux.'
u += 'perso.orange.f r/'; u += 'mac/1520/images/gestion_1.gif';
sizeImg('http://'+u);return false;">try by cache</a>
</html>

IE6: first try = 30, try by cache = 447
FF1.5: first try = 0, try by cache = 447
Dec 5 '06 #9
ASM
pcx99 a écrit :
ASM wrote:
>>>
Could you try with :
First try: 0
second try: 447w 339h
Jim Land a écrit :
>
IE6: first try = 30, try by cache = 447
FF1.5: first try = 0, try by cache = 447
Thanks both of you.

I'ld like 'naixn' tries too and can see differences between two calls.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3921
by: Jeremy Cowles | last post by:
I have been reading a book that focuses on understanding the intrinsic types of C++ in depth. The author's mentality is this: "Understand the intrinsic types, then learn the std types as needed later", but I have been reading the stroustrup (spelling?) book and he says that it is much better to learn the standard library first as a beginner, and then worry about the intrinsic types afterwards. So there is no doubt that you need to have a...
9
4086
by: Deepa | last post by:
Hi All, I'm facing problem displaying image of size 5000X5000 .My window size is smaller than image size so i'm not able to see the complete image.i can use scroll bars to view the image but i need to rotate the image and the see the result everytime. For this my boss has given me suggestion to display only 20% of the image on window ,and rotation has to be applied to original copy.
4
16660
by: no-spam | last post by:
Hello, I have an HTML question that I'm not sure can be solved. I want to restrict the maximum size of an inline image. For example, I can force the image to be 200x200 if I do this: <img src=blah.gif width=200 height=200> But, that messes up the aspect ratio, and could size the image larger than it's original size.
3
3957
by: George M. Garner Jr. | last post by:
Is there an intrinsic to wrap the bswap x86 instruction. I have written a function to do this with inline assembler but I am wondering if an intrinsic wouldn't be a better solution. Regards, George.
2
8526
by: Sanjeeva Reddy | last post by:
hai Anti Keskinen, i have used the following code MyListView->LargeImageList->ImageSize = gcnew System::Drawing::Size(100, 100); // Sets large image size to 100, 100 here i am getting error like "gcnew is undeclared error",how to deeclare 'gcnew" and when i am using in runtime to change the size of images in imagelist in listview control in .net(forms application) by chnging one trckbar(like tb1->Value),
13
3272
by: Alek Davis | last post by:
Hi, Is it possible to access intrinsic ASP objects, such as Request, from a .NET class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can this library retrieve the request info (basically, server variables exposed via the Request object), when it is invoked from a traditional ASP (not ASP.NET) application? Any ideas? Thanks in advance. Alek
16
1842
by: Frederick Gotham | last post by:
Inspired by page 219 of Nicolai M. Josuttis's book, I set out to write a class for an intrinsic array which would behave, to as far an extent as possible, like a container. Also though, I wanted no overhead whatsoever. The code I'm about to show below is not finished, it may contain the odd oversight, bug or error (but at a quick glance it seems OK). First of all though, I want to show you some macros I've written. The purpose of the...
1
2924
by: RYKLOU | last post by:
I am kinda new to php, but i do know what i am doing kinda, but i came across this error when i am trying to upload a file to my website. Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 3714000 bytes) in /opt/lampp/htdocs/tutorials/php-mysql-tutorial/admin/image-gallery/library/functions.php on line 104 Platform: Ubuntu 8.04 LST (where i make my programs, and test them before i upload them), Using XAMPP for...
0
10751
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7333
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.