image size

S

sbrixner

Is there a way of retrieving the size of an image located on the server?
Thanks. Steve Brixner
 
S

Steve Easton

Do you mean height and width or file size??

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
S

sbrixner

The height and width in pixels. Thanks. Steve.

Steve Easton said:
Do you mean height and width or file size??

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
S

Steve Easton

That's easy. Funny you should ask, I'm working on a script that will automatically display any size
image in the appropriate window, simply by reading the image size and then creating the window.


The following will return the dimensions of an image.


<SCRIPT type=text/javascript>
function getsize(img){
imga = new Image();
imga.src=(img);
sizew=eval(imga.width);
sizeh=eval(imga.height);
alert("width="+sizew+",height="+sizeh);
</script>


To make it work, use an onclick event containing the name of the image you want to find the
dimensions of
like this

onclick="getsize(imagename.jpg)

With this one the image needs to be in the same location as the page running the script.

hth

Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
S

Steve Easton

oops. Change the onclick to this:

onclick="getsize('imagename.jpg')

Note the hyphens.
--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
M

Murray

hyphens?

--
Murray

Steve Easton said:
oops. Change the onclick to this:

onclick="getsize('imagename.jpg')

Note the hyphens.
--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
.......................with a computer
 
S

Steve Easton

LOL.

apostrophe's, some folks call them single quotes.

T'was a long day.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
S

Steve Easton

The script also needs a closing }

<SCRIPT type=text/javascript>
function getsize(img){
imga = new Image();
imga.src=(img);
sizew=eval(imga.width);
sizeh=eval(imga.height);
alert("width="+sizew+",height="+sizeh);
}
</script>


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
S

sbrixner

Thanks very much. I have implemented a revised script on my page. There
seems to be a limit as to how small a window can be, and it doesn't seem to
work in Firefox. Works in Netscape 7 but is a bit slow. You can see the
results at:

http://www.brixnerdesign.net/milton/catalog.asp

As you move the mouse pointer over the titles, a thumbnail image will appear
if one exists. The more recent the date, the more likely there is to be an
image.

Steve Brixner
 
S

Steve Easton

Interesting.
Declaring the variables as global really isn't necessary, but it doesn't hurt anything.

Haven't gotten it to work correctly in Mozilla, Netscape, Firefox yet . But I think the issue is
that the margin info written to the popup has to be set with a style tag rather than inline

Also, I think it's easier if you create a string variable and then use the variable in window.open
like this.

sVar1="left=20"+",top=20"+",Width="+sizew+",Height="+sizeh;

then

newwindow=window.open('','',sVar1);

Here's my "test" page. Haven't tested it in XP SP 2 or Firefox though, so it may be "quirky."

http://www.95isalive.com/test/

the script is in the page.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
S

sbrixner

When I first open your page and click on an image, the alert box reports the
width and height as 0. The windows open to about 800 x 600 px. The second
time I click on an image the width and height are reported correctly and the
small window opens. This is using IE6. Thanks for your help. Steve Brixner.
 
S

Steve Easton

Thanks,
I was probably "playing" with it at the time, rearranging the order of the scripting.

I was trying to create a setTimeout in the script to give it a little more time to query the server
before creating the new window to ensure the values were retuned properly.

Instead I just moved the line that concatenates the string variable to a position below the
HTMLstring to ensure that the HTMLstring is created and ready to write when the window is opened.
Seems to work better.

There should be no alerts and it "should" work properly now.


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top