474,044 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting width and height from a picture file

Greetings.

Is there any way, in Javascript, to put in 2 variables the width and
height of a picture, given the filename and without the picture being
displayed in the webpage?

Thank you,
Joaquim Amado Lopes

Feb 6 '08 #1
6 2153
Joaquim Amado Lopes wrote on 07 feb 2008 in comp.lang.javas cript:
Is there any way, in Javascript, to put in 2 variables the width and
height of a picture, given the filename and without the picture being
displayed in the webpage?
Just put the img outside the viewable window

style='position :absolute;left:-1000px;'

and then measure it.

I think.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 6 '08 #2
Greetings.

On 06 Feb 2008 23:06:41 GMT, "Evertjan."
<ex************ **@interxnl.net wrote:
>Is there any way, in Javascript, to put in 2 variables the width and
height of a picture, given the filename and without the picture being
displayed in the webpage?

Just put the img outside the viewable window

style='positio n:absolute;left :-1000px;'

and then measure it.

I think.
It's not practical for what I need.

I have a form to publish articles, in which the user chooses the
picture to display with the article.
The list of pictures is collected from a folder and presented in a
SELECT form field. As the user chooses one of the items on the list
(onChange), that picture is previewed.

As some of the pictures may be quite large and must be previewed with
reduced dimensions, I need to know the dimensions of each picture
before displaying it, to determine the width and height of the preview
and maintain the proportions.

Cheers,
Joaquim Amado Lopes

Feb 6 '08 #3
Joaquim Amado Lopes <ja*****@jalope s.net.writes:
Greetings.

On 06 Feb 2008 23:06:41 GMT, "Evertjan."
<ex************ **@interxnl.net wrote:
>>Is there any way, in Javascript, to put in 2 variables the width and
height of a picture, given the filename and without the picture being
displayed in the webpage?

Just put the img outside the viewable window

style='positi on:absolute;lef t:-1000px;'

and then measure it.

I think.
It's not practical for what I need.

I have a form to publish articles, in which the user chooses the
picture to display with the article.
The list of pictures is collected from a folder and presented in a
SELECT form field. As the user chooses one of the items on the list
(onChange), that picture is previewed.

As some of the pictures may be quite large and must be previewed with
reduced dimensions, I need to know the dimensions of each picture
before displaying it, to determine the width and height of the preview
and maintain the proportions.
Then you may be out of luck: to determine the dimensions you *will* have
to examine the content of the image stream. How much of the content
you'll need is dependent on the type of image. You may need most or all
of it.

You could possibly be able to hack something together for the major file
types using Ajax, but I would suggest you move all of that to the
server, where there are plenty of libraries and resources that will
handle this much better.

Joost.
Feb 6 '08 #4
Greetings.

On Thu, 07 Feb 2008 00:42:31 +0100, Joost Diepenmaat <jo***@zeekat.n l>
wrote:
[snip]
>I have a form to publish articles, in which the user chooses the
picture to display with the article.
The list of pictures is collected from a folder and presented in a
SELECT form field. As the user chooses one of the items on the list
(onChange), that picture is previewed.

As some of the pictures may be quite large and must be previewed with
reduced dimensions, I need to know the dimensions of each picture
before displaying it, to determine the width and height of the preview
and maintain the proportions.

Then you may be out of luck: to determine the dimensions you *will* have
to examine the content of the image stream. How much of the content
you'll need is dependent on the type of image. You may need most or all
of it.

You could possibly be able to hack something together for the major file
types using Ajax, but I would suggest you move all of that to the
server, where there are plenty of libraries and resources that will
handle this much better.
I wasn't clear in my previous post. The images are on the server.
The upload part is already working.

Cheers,
Joaquim Amado Lopes

Feb 7 '08 #5
Joaquim Amado Lopes <ja*****@jalope s.net.writes:
>>As some of the pictures may be quite large and must be previewed with
reduced dimensions, I need to know the dimensions of each picture
before displaying it, to determine the width and height of the preview
and maintain the proportions.

Then you may be out of luck: to determine the dimensions you *will* have
to examine the content of the image stream. How much of the content
you'll need is dependent on the type of image. You may need most or all
of it.

You could possibly be able to hack something together for the major file
types using Ajax, but I would suggest you move all of that to the
server, where there are plenty of libraries and resources that will
handle this much better.
I wasn't clear in my previous post. The images are on the server.
The upload part is already working.
Well, if you know the dimensions on the server, just use an Ajax to
fetch them:

http://developer.mozilla.org/en/docs...etting_Started

Note that that text uses XML in the response. It's usually easier and
faster to use a javascript response and eval() it to parse the data.
See also http://www.json.org/

Joost.
Feb 7 '08 #6
Joaquim Amado Lopes wrote on 07 feb 2008 in comp.lang.javas cript:
Greetings.

On 06 Feb 2008 23:06:41 GMT, "Evertjan."
<ex************ **@interxnl.net wrote:
>>Is there any way, in Javascript, to put in 2 variables the width and
height of a picture, given the filename and without the picture being
displayed in the webpage?

Just put the img outside the viewable window

style='positi on:absolute;lef t:-1000px;'

and then measure it.

I think.
It's not practical for what I need.

I have a form to publish articles, in which the user chooses the
picture to display with the article.
The list of pictures is collected from a folder and presented in a
SELECT form field. As the user chooses one of the items on the list
(onChange), that picture is previewed.

As some of the pictures may be quite large and must be previewed with
reduced dimensions, I need to know the dimensions of each picture
before displaying it, to determine the width and height of the preview
and maintain the proportions.
Doing this clientside without downloading seems impossible.

I suppose you better use a serverside javascript solution, like:

http://www.aspjpeg.com/object_aspjpe...OriginalHeight
http://www.aspjpeg.com/object_aspjpe...#OriginalWidth
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 7 '08 #7

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

Similar topics

15
2155
by: middletree | last post by:
How do I request the actual page name that I'm on? This is going to go into an include file, and depending on which page I'm on, I'd like to do different things. I'm looking for "pagename.asp"
1
1939
by: Mustafa Rabie | last post by:
dear all, i am writing an application where the user can upload his own picture. I wanted to get the Width and Height of the uploaded picture. So i assigned the uploaded image to an aspnet image control, but when i call the height and width properties of the image control it returns "" since they are not set. So how can i get this info? thanks mustafa
3
3114
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are displayed. Can anybody know this issue and help me to resolve this. In past i received the response saying that i should download the image first and then parse the actual response and modify the src attribute of the
4
3498
by: Doug van Vianen | last post by:
Hi, I have the following coding on a web page. It causes two pictures (pic1.jpg and pic2.jpg) to show, one above the other and then when one clicks on the top picture is squeezes to the left (as its width is reduced) to show the bottom picture. Then when the bottom picture is clicked the top picture expands to the right to cover the bottom picture again.
18
2247
by: pecan | last post by:
I have hundreds of pictures on my site. The thumbnails are all a standard size, and most of the bigger ones are the same size too. When I run my html code through my optimizer it throws out a warning if I don't have an image size in the html, but I want to put that into the CSS instead, and clean up my html code. What's more important, having the IMG size in the html, or minimalised code? I knwo the theory behind the size in html is so...
3
1799
by: find clausen | last post by:
Is it possible to get the width of a picture: <img src="../graphics/press/bw21.jpg" width=400 height=555 alt="" border="0"> the make a box be exactly the width of the picture: document.write('<div class="box" style="width:'+ w +'px">');
1
4212
epots9
by: epots9 | last post by:
I have a image inside of a div <div id="image"> <div id="loader"> <img id="loaderImage" src="assets/loader.gif" alt="loading..." /> </div> <div id="loaded"> <img id="picture" src="" alt="" /><!--image in question--> <div id="closeAll" onclick="closeAll();">X</div> </div>
9
2169
by: Summercool | last post by:
I wonder to show the images in a table format... and to set a box of width 100px and height 100px, is there a way? Right now, if I set width to 100px, then height can be 180px... If I set height to 100px, then width can be 260px... What I really want is, to have the greatest width and greatest height so long as none of them exceed 100px, and maintaining the aspect ratio. (I don't want to set both width and height to 100px for the
9
2645
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of the main floors of the main house: Part C: Gross Floor Area of the basement or cellar: Part D: Gross Floor Area of the attic:
0
10546
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
11602
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
12022
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,...
1
8698
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
7868
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
6652
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
6836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3971
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.