Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
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
Old 2005-11-24, 03:24 AM   #2
oast
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
 
oast's Avatar
 
Join Date: May 2004
Location: UK
Posts: 316
Subway
In my (little) experience with GD, this is usually due to a corrupt (or less than perfect) image file.
Have you tried other images from different sources?
Is there any indication in the php error log (assuming you have one)?
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare.
oast is offline   Reply With Quote
Old 2005-11-24, 06:08 AM   #3
oast
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
 
oast's Avatar
 
Join Date: May 2004
Location: UK
Posts: 316
Would have edited previous message, but option was not there as it was a "Quick Reply"

Any way, I played with this and moved the imageCreateFromJPEG function above the image sizing functions. Also used full paths.

So try this:
Code:
function do_thumbs( $fn ){
  $img_src    = "/home/user/rep_pics/large/".$fn;

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

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

$med_source_handle = imageCreateFromJPEG($img_src);
if(!$med_source_handle){ die("couldn't get the source handle - $img_src"); }
$sml_source_handle = imageCreateFromJPEG($img_src);
if(!$sml_source_handle){ die("couldn't get the source handle - $img_src"); }

  $src_height = ImageSY($med_source_handle);
  $src_width  = ImageSX($med_source_handle);
  $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);
  imageDestroy($med_source_handle);

  $src_height = ImageSY($sml_source_handle);
  $src_width  = ImageSX($sml_source_handle);
  $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);
  imageDestroy($sml_source_handle);
}
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare.
oast is offline   Reply With Quote
Old 2005-11-24, 10:16 AM   #4
Subway
Internet! Is that thing still around?
 
Join Date: Nov 2005
Posts: 3
Ya I got it figured out finally. My host had error messages turned off so it was a pain in the ass to figure out.. I finally got GD set up right on my local test bed and it all started making sense . Here's the 'finished' code if anyone ever needs it.

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;

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

  $med_image  = imageCreateTrueColor( $med_width, $med_height );
  imageCopyResampled($med_image, $source_handle, 0, 0, 0, 0, $med_width, $med_height, $src_width, $src_height );
  imageJPEG($med_image, $med_dest, 90);
  chmod($med_dest, 0777);
  imageDestroy($med_image);
  
  $sml_image  = imageCreateTrueColor( $sml_width, $sml_height );
  imageCopyResampled($sml_image, $source_handle, 0, 0, 0, 0, $sml_width, $sml_height, $src_width, $src_height );
  imageJPEG($sml_image, $sml_dest, 90);
  chmod($sml_dest, 0777);
  imageDestroy($sml_image);
}
Subway is offline   Reply With Quote
Old 2005-11-24, 10:07 PM   #5
oast
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
 
oast's Avatar
 
Join Date: May 2004
Location: UK
Posts: 316
One quick question...

Why are you making the final thumbnails world writable and executable? (chmod 777)?
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare.
oast is offline   Reply With Quote
Old 2005-11-24, 11:02 PM   #6
Subway
Internet! Is that thing still around?
 
Join Date: Nov 2005
Posts: 3
Because when theyre created by php they're owned by apache and I cannot delete or rename them via FTP. I have a tendancy to change my mind about stuff all the time so I tend to run in to situations where I need to do something with them... no other reason.
Subway is offline   Reply With Quote
Old 2005-11-25, 07:23 PM   #7
tickler
If there is nobody out there, that's a lot of real estate going to waste!
 
tickler's Avatar
 
Join Date: Dec 2003
Posts: 2,177
I use basically the same code. Only difference is that I use imageCopy() instead of inmageCopyResampled().
__________________
Latina Twins, Solo, NN, Hardcore
Latin Teen Cash
tickler is offline   Reply With Quote
Old 2005-11-26, 11:08 AM   #8
oast
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
 
oast's Avatar
 
Join Date: May 2004
Location: UK
Posts: 316
Quote:
Originally Posted by tickler
I use basically the same code. Only difference is that I use imageCopy() instead of inmageCopyResampled().
Doesn't imageCopyResampled() give better results when resizing an image?


Just noticed this:
Quote:
Originally Posted by Subway
imageJPEG($sml_image, $sml_dest, 90);
Why use 90% on thumbnails when web/JPEG default is 75?

In response to your earlier reply:
chown(new_image, username);
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare.
oast is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:29 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc