[Request] I am looking for a high-quality JPG resize/optimize function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ragnorack67@hotmail.com

    [Request] I am looking for a high-quality JPG resize/optimize function

    Hi, I am looking for a complete PHP function that will resize &
    optimize any JPG image with very good end results. My server is
    running PHP 4.3.8.

    So, for instance a 1600x1200 JPG at ../somewhere/picture.jpg

    could be read by the function and save where I specify like
    .../somewhere/pictureResized. jpg

    .....what is most important for me besides a good end result is the
    function should calculate which side of the image is larger, and based
    on a maximum value I preset (like 800), adjust the image proportionally
    to 800x600 (for example).

    Thanks so much for anyone's assistance with this!

    BEST REGARDS -

    ALEX

  • Daniel Tryba

    #2
    Re: [Request] I am looking for a high-quality JPG resize/optimize function

    In comp.lang.php Ragnorack67@hot mail.com wrote:[color=blue]
    > So, for instance a 1600x1200 JPG at ../somewhere/picture.jpg
    >
    > could be read by the function and save where I specify like
    > ../somewhere/pictureResized. jpg[/color]

    imagejpeg($newi mage,$pathtores izedpicture)
    [color=blue]
    > ....what is most important for me besides a good end result is the
    > function should calculate which side of the image is larger, and based
    > on a maximum value I preset (like 800), adjust the image proportionally
    > to 800x600 (for example).[/color]

    Almost trivial, see the function resize() in


    used to serve reduced images from raw jpegs created by a camera
    (http://jamie.tryba.nl/slideshow.php)

    Comment

    • Ragnorack67@hotmail.com

      #3
      Re: I am looking for a high-quality JPG resize/optimize function

      Could you pls help me with actual implementation of this, so if I have
      a 1600x1200 picture, how to tell it where it is, and where to save a
      resized version on the server:

      <?php

      function resize($file,$n x,$ny)
      {
      $image=imagecre atefromjpeg($fi le);

      $x=imagesx($ima ge);
      $y=imagesy($ima ge);
      $r=$x/$y;

      $mr=$nx/$ny;

      if($r>$mr)
      {
      $f=$x/$nx;
      }
      else
      {
      $f=$y/$ny;
      }

      $nx=round($x/$f);
      $ny=round($y/$f);

      $newimage=image createtruecolor ($nx,$ny);
      imagecopyresamp led($newimage,$ image,0,0,0,0,$ nx,$ny,$x,$y);

      return $newimage;
      }

      ?>

      Comment

      • Peter Albertsson

        #4
        Re: [Request] I am looking for a high-quality JPG resize/optimize function



        Regards,

        Peter

        <Ragnorack67@ho tmail.com> wrote in message
        news:1111023862 .379117.150770@ g14g2000cwa.goo glegroups.com.. .[color=blue]
        > Hi, I am looking for a complete PHP function that will resize &
        > optimize any JPG image with very good end results. My server is
        > running PHP 4.3.8.
        >
        > So, for instance a 1600x1200 JPG at ../somewhere/picture.jpg
        >
        > could be read by the function and save where I specify like
        > ../somewhere/pictureResized. jpg
        >
        > ....what is most important for me besides a good end result is the
        > function should calculate which side of the image is larger, and based
        > on a maximum value I preset (like 800), adjust the image proportionally
        > to 800x600 (for example).
        >
        > Thanks so much for anyone's assistance with this!
        >
        > BEST REGARDS -
        >
        > ALEX
        >[/color]


        Comment

        • Caspar Kleijne

          #5
          Re: [Request] I am looking for a high-quality JPG resize/optimize function

          ALEX,

          There are many different ways of scaling an image.

          depending on the amount of detail and amount of colors in the original, you
          should use different methods. It is sometimes better not to scale an image
          at once, but in several steps instead, where each step isn't bigger than
          49% scaleing, to preserve quality.

          one simple php-script should be like this:


          <?php
          // The file
          $filename = 'test.jpg';
          $outputfilename = "/somewhere/picture.jpg";

          // Set a maximum height and width
          $width = 200;
          $height = 200;

          // Get new dimensions
          list($width_ori g, $height_orig) = getimagesize($f ilename);

          if ($width && ($width_orig < $height_orig)) {
          $width = ($height / $height_orig) * $width_orig;
          } else {
          $height = ($width / $width_orig) * $height_orig;
          }

          // Resample
          $image_p = imagecreatetrue color($width, $height);
          $image = imagecreatefrom jpeg($filename) ;
          imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $width, $height,
          $width_orig, $height_orig);

          // Output
          imagejpeg($imag e_p, $outputfilename , 100);
          ?>

          play with it..

          more you can find on:


          greetings Caspar.




          Comment

          Working...