Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2002, 03:22 PM   PM User | #1
MikoLone
Regular Coder

 
Join Date: Jun 2002
Location: Provo, UT
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
MikoLone is an unknown quantity at this point
Thumbs up can you check image file properties using javascript.

I have this script where you pass the a popup window the size that will fit the image so that it will be the same size as the picture. I was wondering if it is possible in javascript to check out the size of the picture so that I do not have to pass the size I want to the window. Is it possible?

Thanks for the imput.
MikoLone is offline   Reply With Quote
Old 07-17-2002, 05:26 PM   PM User | #2
tamienne
Regular Coder

 
Join Date: Jun 2002
Location: Delaware, USA
Posts: 138
Thanks: 0
Thanked 0 Times in 0 Posts
tamienne is an unknown quantity at this point
The image needs to be loaded before you can access it's properties. So, it's not really possible to do it unless you want to load the image twice...
tamienne is offline   Reply With Quote
Old 07-17-2002, 05:40 PM   PM User | #3
MikoLone
Regular Coder

 
Join Date: Jun 2002
Location: Provo, UT
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
MikoLone is an unknown quantity at this point
do you mean like preloading it? I am down to load them twice, I just need to know how. Do you have a script that might help me along?
MikoLone is offline   Reply With Quote
Old 07-17-2002, 06:34 PM   PM User | #4
x_goose_x
Regular Coder

 
Join Date: Jun 2002
Location: Montreal, Canada
Posts: 644
Thanks: 0
Thanked 0 Times in 0 Posts
x_goose_x is an unknown quantity at this point
<script>

function popupimag(file,bg,col) {
pophtml = "<body bgcolor='"+bg+"'><img src='"+file+"' style='position:absolute; left:0; top:0;'><div style='position:absolute; left:0; width:100%; color:"+col+"; text-align:center;' id='cls' onclick='self.close();'>[Close]</div></body>";
pop = window.open("","","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizabl e=no,");
pop.document.write(pophtml)
w = pop.document.images[0].width+10;
h = pop.document.images[0].height+50;
pop.document.getElementById("cls").style.top = h - 50;
pop.resizeTo(w,h);
}

</script>

<a href="javascript: popupimag('imag.jpg','black','red');">pop</a>
x_goose_x is offline   Reply With Quote
Old 07-17-2002, 06:47 PM   PM User | #5
Hawk
New Coder

 
Join Date: Jul 2002
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Hawk is an unknown quantity at this point
Re: can you check image file properties using javascript.

Quote:
Originally posted by MikoLone
I have this script where you pass the a popup window the size that will fit the image so that it will be the same size as the picture.
MikoLone, is there any way you can post that script because I am looking for something like that.

Thanks
Hawk is offline   Reply With Quote
Old 07-17-2002, 06:49 PM   PM User | #6
Hawk
New Coder

 
Join Date: Jul 2002
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Hawk is an unknown quantity at this point
Actually, I think x_goose_x's example does the samething.
Hawk is offline   Reply With Quote
Old 07-17-2002, 09:32 PM   PM User | #7
MikoLone
Regular Coder

 
Join Date: Jun 2002
Location: Provo, UT
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
MikoLone is an unknown quantity at this point
Thanks goose it works great.

I never thought about using %s for the width of the picture. Cool
MikoLone is offline   Reply With Quote
Old 07-18-2002, 12:24 AM   PM User | #8
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
Gecko makes this easy:

var newWin = window.open('bla.gif');
newWin.sizeToContent();

OR:

var image = new Image('bla.gif');
var newWin = window.open('bla.gif','','width=' + image.naturalWidth + ',height=' + image.naturalHeight);

__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:47 AM.


Advertisement
Log in to turn off these ads.