473,608 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to find image dimensions?

Is there a way in javascript to find out the size of an image you've just
preloaded?

I have the following object:

function tourImage(imgNa me) {
// used for passing image details to a function.
this.name=imgNa me;
//this.imgLoadImg = document.getEle mentById("imgLo adImg");
function preload(callbac k) {
this.img=new Image();
this.img.src=th is.name;
// call tour.showPano when the image has loaded.
this.img.onLoad =this.runCallba ck(callback);
};
this.preload=pr eload;
function runCallback(cb) {
// first do what's needed for every image.
// puit this image into the hidden image container to find the size.
//this.imgLoadImg .src=this.name;
//this.width=this .imgLoadImg.wid th;
//this.height=thi s.imgLoadImg.he ight;
//this.imgLoadImg .src="";
this.height=tou r.resolution;
*** // TODO - fix this so it finds the image size automatically.
this.width=tour .resolution*6.8 89;
this.ratio=this .width / this.height;
// then call the callback function.
cb();
}
this.runCallbac k=runCallback;
};

what I want to do is fix this so it finds out the size of the just-loaded
image by itself, so that the true image dimensions can be used to scale
the image properly.

I've tried using this.img.width; I've also tried loading the image into a
dummy img tag with no width and height properties to see if I can get the
details that way, but that doesn't work either.

can anyone suggest a good way of doing this?

--
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line.

May 27 '06 #1
3 2489
Andy Baxter said:
Is there a way in javascript to find out the size of an image you've just
preloaded?

I have the following object:

function tourImage(imgNa me) {
// used for passing image details to a function.
this.name=imgNa me;
//this.imgLoadImg = document.getEle mentById("imgLo adImg");
function preload(callbac k) {
this.img=new Image();
this.img.src=th is.name;
// call tour.showPano when the image has loaded.
this.img.onLoad =this.runCallba ck(callback);
};
this.preload=pr eload;
function runCallback(cb) {
// first do what's needed for every image.
// puit this image into the hidden image container to find the size.
//this.imgLoadImg .src=this.name;
//this.width=this .imgLoadImg.wid th;
//this.height=thi s.imgLoadImg.he ight;
//this.imgLoadImg .src="";
this.height=tou r.resolution;
*** // TODO - fix this so it finds the image size automatically.
this.width=tour .resolution*6.8 89;
this.ratio=this .width / this.height;
// then call the callback function.
cb();
}
this.runCallbac k=runCallback;
};

what I want to do is fix this so it finds out the size of the just-loaded
image by itself, so that the true image dimensions can be used to scale
the image properly.

I've tried using this.img.width; I've also tried loading the image into a
dummy img tag with no width and height properties to see if I can get the
details that way, but that doesn't work either.

can anyone suggest a good way of doing this?


Sorry - this should have been posted to comp.lang.javas cript.
--
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line.

May 27 '06 #2
Andy Baxter <ne***@earthson g.null.free-online.co.uk> wrote:
Is there a way in javascript to find out the size of an image you've just
preloaded?


The groups in the comp.infosystem s.www.authoring.* hierarchy have a
fairly strict policy on what's on topic. The topic for this group is
HTML.

comp.languages. javascript is the right place for this question.

--
Spartanicus
May 27 '06 #3
Spartanicus said:
Andy Baxter <ne***@earthson g.null.free-online.co.uk> wrote:
Is there a way in javascript to find out the size of an image you've just
preloaded?


The groups in the comp.infosystem s.www.authoring.* hierarchy have a
fairly strict policy on what's on topic. The topic for this group is
HTML.

comp.languages. javascript is the right place for this question.


Sorry - I posted here by mistake.

--
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line.

May 27 '06 #4

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

Similar topics

3
11752
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
8
9437
by: Abs | last post by:
Hi! I have an image inside a DIV box with its dimensions specified. The problem is that I don't know the dimensions of the image beforehand, therefore the image grows outside the box if it's bigger than the box. Is there a way to force the image to resize itself automatically to fit the box with CSS ? Thanks in advance
5
2091
by: John | last post by:
I am rotating images at one location of my web site. My problem is if I set the width and height of the new image before I show the new image, the old image is stretched first to the new image dimensions, and if I show the new image before setting its dimensions, the new image is stretched first to the old image dimension before it is adjusted to its own dimension. I would like to load a new image with its own dimension at the same time....
1
2062
by: John | last post by:
I am rotating images of different dimensions. My problem is that when a new image is displayed in a new position which had an image of a different dimension, the old image is first stretched to the dimension of the new image, before the new image is loaded. How can I stop this stretching behavior? See the banner images on the right at http://finialworld.com thank you John
14
11065
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin = window.open('images/KJV-THANKS.gif', 'Thanks', 'width=243,height=420,'); cwin.focus();
6
9893
by: MurrayTh | last post by:
Is there any way to determine the dimensions of an image using the image's URL? ie load image based on URL, and then get dimensions? or perhaps better method?
2
5547
by: Andy Baxter | last post by:
Is there a way in javascript to find out the size of an image you've just preloaded? I have the following object: function tourImage(imgName) { // used for passing image details to a function. this.name=imgName; //this.imgLoadImg = document.getElementById("imgLoadImg"); function preload(callback) {
1
2494
by: johnrees | last post by:
I am building a photo gallery using code which creates thumbnails of a specific size from any image. When clicked the thumbnail expands dynamically to a pre-determined size. The sizes of the thumbnails and the enlarged image are set via variables. To work properly, all the original images must be the same dimensions which means a great deal of editing and cropping before the images can be posted. And portrait images sometimes cannot be cropped...
2
4119
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this: http://www.pythonware.com/library/pil/handbook/introduction.htm but it looks like it is something I will need to install - I'd like to be able to pass my script around to people without them needing any
0
8063
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8498
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
6817
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
6014
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
5476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
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.