A good image scaling program?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D. Alvarado

    #1

    A good image scaling program?

    Hello,
    Can anyone recommend a good image scaling program for PHP 4. What
    I'm really looking for is just a function that takes an image file and
    a width to which to scale the image and outputs the scaled image.

    I am grateful for anyone's recommendations , - Dave
  • Chris Hope

    #2
    Re: A good image scaling program?

    D. Alvarado wrote:
    [color=blue]
    > Hello,
    > Can anyone recommend a good image scaling program for PHP 4. What
    > I'm really looking for is just a function that takes an image file and
    > a width to which to scale the image and outputs the scaled image.
    >
    > I am grateful for anyone's recommendations , - Dave[/color]

    If you have imagemagick installed on the server that's an easy way to go.
    There's also the GD library which may or may not be installed into PHP.

    The GD functions are in the manual at http://www.php.net/gd

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • Geoff Berrow

      #3
      Re: A good image scaling program?

      I noticed that Message-ID:
      <9fe1f2ad.04110 41921.7928dd7c@ posting.google. com> from D. Alvarado
      contained the following:
      [color=blue]
      > Can anyone recommend a good image scaling program for PHP 4. What
      >I'm really looking for is just a function that takes an image file and
      >a width to which to scale the image and outputs the scaled image.[/color]


      If you use the GD functions I'm not sure if there's a pre written
      function that does it all.

      First you get the dimensions of the uploaded image.
      You need to derive the new image height by some simple maths

      new height = (oldheight/oldwidth)*new width

      Then use imagecopyresamp led to create the new image.

      Lots of code examples about.
      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • 2metre

        #4
        Re: A good image scaling program?

        D. Alvarado wrote:[color=blue]
        > Hello,
        > Can anyone recommend a good image scaling program for PHP 4. What
        > I'm really looking for is just a function that takes an image file and
        > a width to which to scale the image and outputs the scaled image.[/color]
        $src and $tgt are absolute paths to the source file and new image.
        $size will be the maximum dimension (either width or height) of the
        reuslting rescaled image.
        If size isnt given, it will be 150 pixels.


        function createthumb ($src,$tgt,$siz e=150) {
        // create new thumbnail !
        $src_img = imagecreatefrom jpeg($src);
        if ($src_img) {
        // calc portrait or landscape
        if (imagesx($src_i mg) < imagesy($src_im g))
        $scale = imagesy($src_im g) /$size;
        else $scale = imagesx($src_im g) /$size;
        // calc thumbnail dimensions
        $new_w = round(imagesx($ src_img)/$scale);
        $new_h = round(imagesy($ src_img)/$scale);
        // create empty image of correct size & copy/resize image into it
        $dst_img = imagecreatetrue color($new_w,$n ew_h);
        imagecopyresize d($dst_img,$src _img,0,0,0,0,
        $new_w,$new_h,
        imagesx($src_im g),imagesy($src _img));
        imagedestroy($s rc_img);
        // save thumbnail to file
        imagejpeg($dst_ img, $tgt);
        imagedestroy($d st_img);
        }
        else print "<div class=error>fai led to open $src</div>";
        }

        Comment

        • Shawn Wilson

          #5
          Re: A good image scaling program?

          "D. Alvarado" wrote:[color=blue]
          >
          > Can anyone recommend a good image scaling program for PHP 4. What
          > I'm really looking for is just a function that takes an image file and
          > a width to which to scale the image and outputs the scaled image.[/color]

          Try hotscripts.com. But that's also pretty easy to write (at least for JPG and
          PNG) using the GD library.

          Shawn
          --
          Shawn Wilson
          shawn@glassgian t.com

          Comment

          Working...