Hello everyone-<br /><br />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.<br /><br />This is to enable the user to resize the pic without having to use an image editing program.<br /><br />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!<br /><br />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.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->//RESIZE IMAGE FOR THUMBNAIL<br /> Â $image = 'uploads/mypicture640x480.jpg';<br /> Â <br /> Â if (!$max_width)<br /> Â Â $max_width = 80;<br /> Â if (!$max_height)<br /> Â Â $max_height = 60;<br /> Â Â <br /> Â $size = GetImageSize($image);<br /> Â $width = $size[0];<br /> Â $height = $size[1];<br /> Â <br /> Â $x_ratio = $max_width / $width;<br /> Â $y_ratio = $max_height / $height;<br /> Â <br /> Â if ( ($width <= $max_width) && ($height <= $max_height) ){<br /> Â Â $tn_height = ceil($x_ratio * $height);<br /> Â Â $tn_width = $max_width;<br /> Â }<br /> Â else{<br /> Â Â $tn_width = ceil($y_ratio * $width);<br /> Â Â $tn_height = $max_height;<br /> Â }<br /> Â <br /> Â $src = <!-- m --><a class="postlink" href="http://www.totalchoicehosting.com/forums/lofiversion/index.php/ImageCreateFromJPEG(&">http://www.totalchoicehosting.com/forum ... JPEG(&</a><!-- m -->#036;image);<br /> Â $dst = ImageCreate($tn_width,$tn_height);<br /> Â ImageCopyResized($dst,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);<br /><br /> Â //SAVES THE FILE AS A NEW NAME<br /> Â $filename = "uploads/mynew80x60pic.jpg";<br /> Â ImageJPEG($dst,$filename);<br /> Â header('Content-type: image/jpeg');<br /> Â ImageJPEG($dst,null,-1);<br /> Â ImageDestroy($src);<br /> Â ImageDestroy($dst);<!--c2--></div><!--ec2--><br /><br />If anyone could provide insight, thatd be great. Thanks!!<br /><br />Sarah<!--content-->
Hi Sarah, after a quick search I found this <a href="http://de.php.net/imagecopyresized" target="_blank">Link</a> 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...<br />Wish I could be of more assistance <br />RobertM<!--content-->
Hello again-<br /><br />I read the link that Robert had posted, and I used 'imagecopyresampled' rather than 'imagecopyresized' and it displayed no problem! <br /><br />That's all I needed - thanks so much!!!!!<br /><br /><br />Sarah<!--content-->
Glad you got it working! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->
Hi Sarah, after a quick search I found this <a href="http://de.php.net/imagecopyresized" target="_blank">Link</a> 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...<br />Wish I could be of more assistance <br />RobertM<!--content-->
Hello again-<br /><br />I read the link that Robert had posted, and I used 'imagecopyresampled' rather than 'imagecopyresized' and it displayed no problem! <br /><br />That's all I needed - thanks so much!!!!!<br /><br /><br />Sarah<!--content-->
Glad you got it working! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->