Jump to content

Recommended Posts

Posted

Hello everyone-

 

I am making a PHP script that allows for a JPG upload of a 640x480 picture, and will resize it to a thumbnail size and resave the picture on the fly.

 

This is to enable the user to resize the pic without having to use an image editing program.

 

Anyways, I wrote the script that uploads it, and it resaves it as a smaller pic (80x60), but when I open it up to see it, it's lost all of its color!

 

I don't know much about PHP image functions, but maybe someone could tell me what's going on. I'll post some of my code.

 

>//RESIZE IMAGE FOR THUMBNAIL
 $image = 'uploads/mypicture640x480.jpg';
  
 if (!$max_width)
   $max_width = 80;
 if (!$max_height)
   $max_height = 60;
   
 $size = GetImageSize($image);
 $width = $size[0];
 $height = $size[1];
 
 $x_ratio = $max_width / $width;
 $y_ratio = $max_height / $height;
 
 if ( ($width <= $max_width) && ($height <= $max_height) ){
   $tn_height = ceil($x_ratio * $height);
   $tn_width = $max_width;
 }
 else{
   $tn_width = ceil($y_ratio * $width);
   $tn_height = $max_height;
 }
 
 $src = ImageCreateFromJPEG($image);
 $dst = ImageCreate($tn_width,$tn_height);
 ImageCopyResized($dst,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);

 //SAVES THE FILE AS A NEW NAME
 $filename = "uploads/mynew80x60pic.jpg";
 ImageJPEG($dst,$filename);
 header('Content-type: image/jpeg');
 ImageJPEG($dst,null,-1);
 ImageDestroy($src);
 ImageDestroy($dst);

 

If anyone could provide insight, thatd be great. Thanks!!

 

Sarah

Posted

Hi Sarah, after a quick search I found this Link It describes what your experiencing. I am not sure if this will help you or not but It seems to explain why your seeing a blank image...

Wish I could be of more assistance

RobertM

Posted

Hello again-

 

I read the link that Robert had posted, and I used 'imagecopyresampled' rather than 'imagecopyresized' and it displayed no problem!

 

That's all I needed - thanks so much!!!!!

 

 

Sarah

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...