This will resize JPG images:

function get_image_width($image)
{
  $imgsize = getimagesize($image);

  return $imgsize[0];
}

function get_image_height($image)
{
  $imgsize = getimagesize($image);

  return $imgsize[1];
}

function resize_image($originalimage, $dest_width, $save_path, $newfilename)
{
  $file_ext = strstr($newfilename, '.');

  $width = get_image_width($save_path.$originalimage);
  $height = get_image_height($save_path.$originalimage);

// If the width is bigger than the destination width, reduce the image size.
  if ($width > $dest_width)
    {
      $aspectratio = ($width-$dest_width)/$width;

      $newwidth = ceil($dest_width);
      $newheight = ceil($height-($height*$aspectratio));

      if (strtoupper($file_ext) == ".JPG")
        if (function_exists("imagejpeg"))
          {
            $src_img = imagecreatefromjpeg($save_path.$originalimage);

            if (imageistruecolor($src_img))
              $dst_img = imagecreatetruecolor($newwidth, $newheight);
            else
              {
               echo $originalimage." is not a true color image.";
               exit();
               }

            imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $newwidth,
$newheight, $width, $height);
            imagejpeg($dst_img, $save_path.$newfilename, 80);
            imagedestroy($src_img);
            imagedestroy($dst_img);
          }

    }

// Must be the same width or less, just save it.
  else
    if (!copy($save_path.$originalimage, $save_path.$newfilename))
      {
        echo "unable to copy file";
        exit();
      }

  return $newfilename;
}


"Ryan Schefke" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>
> How do you resize pictures once they're in a certain directory?  I have
the
> script to upload a picture, that's working fine.  I just need some help
with
> resizing it.  Can someone help?
>
>
>
> Thanks!
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to