View Single Post
Old 2005-11-23, 04:31 PM   #1
Subway
Internet! Is that thing still around?
 
Join Date: Nov 2005
Posts: 3
Question Help! PHP / GD thumbnail creation

Can anyone see anything wrong with this code?

Code:
function do_thumbs( $fn ){
  $img_src    = "../rep_pics/large/$fn";

  $med_height = 250;
  $med_width  = 200;
  $med_dest   = "../rep_pics/medium/$fn";

  $sml_height = 125;
  $sml_width  = 100;
  $sml_dest   = "../rep_pics/small/$fn";

  $src_height = ImageSY($img_src);
  $src_width  = ImageSX($img_src);

  $med_source_handle = imageCreateFromJPEG($img_src);
  if(!$med_source_handle){ die("couldn't get the source handle - $img_src"); }
  $med_image  = imageCreateTrueColor( $med_width, $med_height );
  imageCopyResampled($med_image, $med_source_handle, 0, 0, 0, 0, $med_width, $med_height, $src_width, $src_height );
  imageJPEG($med_image, $med_dest, 90);
  chmod($img_src, 0777);
  imageDestroy($med_image);
  
  $sml_source_handle = imageCreateFromJPEG($img_src);
  if(!$sml_source_handle){ die("couldn't get the source handle - $img_src"); }
  $sml_image  = imageCreateTrueColor( $sml_width, $sml_height );
  imageCopyResampled($sml_image, $sml_source_handle, 0, 0, 0, 0, $sml_width, $sml_height, $src_width, $src_height );
  imageJPEG($sml_image, $sml_dest, 90);
  chmod($img_src, 0777);
  imageDestroy($sml_image);
}
It's supposed to create two thumbnails given a source image, and it gets as far as creating and even writing the images, but they're just pure black pictures. I've looked over it 1000 times, looked at a dozen tutorials, but can't seem to find where the hangup is. I suppose it would have to be in the imageCopyResampled, but all the function arguments are what they are supposed to be so I'm at a loss. Any help would be greatly appreciated!

Subway
Subway is offline   Reply With Quote