How do I resize an image to a given window size?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert S

    How do I resize an image to a given window size?

    I am writing an image viewer. I want to be able to resize the image so
    that it always fits within a window of given height and width.

    I've tried a couple of these from the web, but the don't seem to take
    into account both the image dimensions AND the window dimensions.

    Are there any algorithms out there? I'm not keen on reinventing the
    wheel here.

  • Jerry Stuckle

    #2
    Re: How do I resize an image to a given window size?

    Robert S wrote:
    I am writing an image viewer. I want to be able to resize the image so
    that it always fits within a window of given height and width.
    >
    I've tried a couple of these from the web, but the don't seem to take
    into account both the image dimensions AND the window dimensions.
    >
    Are there any algorithms out there? I'm not keen on reinventing the
    wheel here.
    >
    It can't be done in PHP. PHP is server-side only, and knows nothing
    about the window dimensions. You would have to use a client-side
    scripting language such as javascript to send the information to the
    server, then have a program resize based on the javascript input.

    But you'll still have problems if the user resizes the window while your
    page is displayed.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Sagari

      #3
      Re: How do I resize an image to a given window size?

      AFAIK, screen dimension can only be accessed with browser-side language
      such as JavaScript. Since PHP has already ended to work when browser
      displays the page, I can suggest using JavaScript to re-open the page
      again, passing screen/window dimensions as parameters.

      Comment

      • pittendrigh

        #4
        Re: How do I resize an image to a given window size?

        Someone wrote: "it can't be done with php alone....you'll need
        javascript too"
        ........and then "you'll still have trouble if they resize the screen
        after sending the html"

        =============== ======
        This got me thinking. I've been working with Google's new
        gwt libraries recently. This is really cool stuff. They use javascript
        and ajax
        like messaging to talk to server, with a system modeled after JavaRMI.
        They take care of the cross-browser-javascript nightmare for you.
        All of a sudden web applications are empowered with drag and drop,
        dynamic resizing, anything you want. Microsft beware. Office suites
        can now be web based applications... .and you'll be able to work on
        your office stuff from an internet cafe in Mongolia, if you want.

        To make this stuff work you write the code in java, and their compiler
        turns (the required client side
        portions) into javascript for you. The PHP community should jump on
        this and make a similar system,
        else be left behind.

        Comment

        • Robert S

          #5
          Re: How do I resize an image to a given window size?


          To make this stuff work you write the code in java, and their compiler
          turns (the required client side
          portions) into javascript for you.
          Sorry - I didn't make myself clear on my original post. I've managed
          to do the javascript code that calculates the size of the window and
          sends it back to the server. I want the PHP code that adjusts the
          image to the dimensions supplied by javascript.

          Comment

          • Rik

            #6
            Re: How do I resize an image to a given window size?

            Robert S <robert.spam.me .senseless@gmai l.comwrote:
            >To make this stuff work you write the code in java, and their compiler
            >turns (the required client side
            >portions) into javascript for you.
            >
            Sorry - I didn't make myself clear on my original post. I've managed
            to do the javascript code that calculates the size of the window and
            sends it back to the server. I want the PHP code that adjusts the
            image to the dimensions supplied by javascript.
            By supplying PHP with the height & width, preferably as GET variables.
            Then you can use the function imagecopyresamp led to scale the image as
            needed. See the examples at http://nl2.php.net/imagecopyresampled.

            Just set the src of the image to be the php script, imagejpg/-png/-gif
            will send the resized image back to the browser as long as you don't
            specify a filename.
            --
            Rik Wasmus

            Comment

            • Robert S

              #7
              Re: How do I resize an image to a given window size?

              Then you can use the function imagecopyresamp led to scale the image as
              needed. See the examples athttp://nl2.php.net/imagecopyresamp led.
              Thanks. Got some good ideas. This this is what I want:


              Comment

              • Chuck Anderson

                #8
                Re: How do I resize an image to a given window size?

                Robert S wrote:
                >Then you can use the function imagecopyresamp led to scale the image as
                >needed. See the examples athttp://nl2.php.net/imagecopyresamp led.
                >>
                >
                Thanks. Got some good ideas. This this is what I want:

                >
                >
                You will find that after resizing (resampling) photos you'll lose some
                image quality, but you can fix that by using an Unsharp Mask. Here's one
                written in Php: http://vikjavev.no/computing/ump.php

                ImageMagick also has a good unsharp mask.

                --
                *************** **************
                Chuck Anderson • Boulder, CO

                *************** **************

                Comment

                • Robert S

                  #9
                  Re: How do I resize an image to a given window size?

                  image quality, but you can fix that by using an Unsharp Mask. Here's one
                  written in Php:http://vikjavev.no/computing/ump.php
                  >
                  ImageMagick also has a good unsharp mask.
                  >
                  Thanks. I've actually used the unsharp mask in ImageMagick for my
                  thumbnails and I've used the PHP one on my script. I think its OK for
                  thumbnails but its pretty slow for a full-sized image.

                  Comment

                  Working...