Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Delaware, USA
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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>

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: can you check image file properties using javascript.

    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

  • #6
    New Coder
    Join Date
    Jul 2002
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, I think x_goose_x's example does the samething.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks goose it works great.

    I never thought about using %s for the width of the picture. Cool

  • #8
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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);



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •