SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member Dream FX Media's Avatar
    Join Date
    Dec 2003
    Location
    Chicago
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Resize image to print on page?

    I have a large image that is located in a folder called "large_image" .
    I want to use javascript to resize that image to a size so that it would fit to page before it is sent to printer. Is that possible

    Thanks for your time.

  2. #2
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming that the browser is full-screen, then the following code should do the trick:

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    var img = new Image();
    img.src = "http://www.yoursite.com/images/the_image.jpg";
    if (img.width > screen.width)
    {
     // Reduce the width so image fits.
     var factor = (screen.width-50)/img.width;
     img.width *= factor;
     img.height *= factor;
    }
    if (img.height > screen.height)
    {
     // Reduce the height so it fits.
     var factor = (screen.height-50)/img.height;
     img.width *= factor;
     img.height *= factor;
    }
    //-->
    </script>
    However, if you choose to fit it within the browser window instead, then use the browser dimensions instead of the screen height and width.

    Hope this helps.
    Kiffin
    Your average future-famous kind of guy...

  3. #3
    SitePoint Member Dream FX Media's Avatar
    Join Date
    Dec 2003
    Location
    Chicago
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Thank you very much for your help. I had been racking my brain for awhile.
    Thanks Again


Bookmarks

Posting Permissions

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