Author Topic: Image resize problem  (Read 2892 times)

0 Members and 1 Guest are viewing this topic.

Offline Angie

  • album.pl User
  • *
  • Posts: 2
  • Karma: +0/-0
Image resize problem
« on: January 26, 2006, 16:54:02 »
Hi!
I wonder if anyone can help me.  I want to resize an uploaded image to 300 width (with proportional height)  if it is greater than 300 width when uploaded.  I have image magick installed on my server but can't find any decent imfo on how to use it.

The bit of the script I wrote to deal with uploaded images so far (without resizing) is:
$upload_dir = "/home/********/public_html/upload";
$query = new CGI;
$filename = $query->param("photo");
$filename =~ s/.*[\/\\](.*)/$1/;
$handle = $query->upload("photo");
open UPLOADFILE, ">$upload_dir/$PPid.jpg";
binmode UPLOADFILE;
while ( <$handle> )
{
    print UPLOADFILE;
}
close UPLOADFILE;
}

That works fine but I really need the pics to be confined to a max of 300 width with proprotionate height.  If anyone could help I would be most grateful.

Thanks
Angie

Offline Mike Bobbitt

  • album.pl Author
  • Administrator
  • I Spend Too Much Time Here
  • *****
  • Posts: 3381
  • Karma: +35/-2
    • Mike's Development Archive
Re: Image resize problem
« Reply #1 on: January 30, 2006, 09:02:35 »
There's really 2 things you need to do:

1. Get the image dimensions so you know if a resize is needed.
2. Resize the image.

If you want, have a look in album.pl, at the getPhotoDimensions subroutine, which handles #1, and genThumb contains the code I used to resize the image for #2. Hopefully that's a good start!