triphis Posted May 8, 2007 Share Posted May 8, 2007 Hey everyone I have managed in the past to do simple image uploading and resizing... but now I want to extend one of my scripts to make a THUMBNAIL of the newly resized image. I am having trouble "capturing" the just-resized image and running it through the same process again. Hopefully someone here can help The code seen below is on a page that accepts image uploads as an array... Thanks in advance! foreach($_FILES['images']['tmp_name'] as $temp) { if($temp != NULL) { $result = mysql_query("SELECT * FROM pictures WHERE productcode = '$productcode'") or die(mysql_error()); $number = mysql_num_rows($result) + 1; if($number == 1) { $main = 1; } else { $main = 0; } $directory = '../uploads/'; $filename = $productcode . "_" . $number . ".jpg"; $newfile = $directory . $filename; $uploadedfile = $temp; $src = imagecreatefromjpeg($uploadedfile); list($width,$height)=getimagesize($uploadedfile); $newwidth=250; $newheight=304; $tmp=imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); $justresized = imagejpeg($tmp,$newfile,100); // is this right??? $thumbdirectory = '../uploads/thumbs/'; $Tfilename = $productcode . "_" . $number . ".jpg"; // same name as before $Tnewfile = $thumbdirectory . $Tfilename; $uploadedfilethumb = $justresized; // I think this is where the problem is $srcthumb = imagecreatefromjpeg($uploadedfilethumb); list($Twidth,$Theight)=getimagesize($uploadedfilethumb); $Tnewwidth=100; $Tnewheight=100; $tmpthumb=imagecreatetruecolor($Tnewwidth,$Tnewheight); imagecopyresampled($tmpthumb,$srcthumb,0,0,0,0,$Tnewwidth,$Tnewheight,$Twidth,$Theight); if (imagejpeg($tmpthumb,$Tnewfile,100)) { echo "The image was uploaded, and the thumbnail was created!"; $entry = "INSERT INTO pictures(id,productcode,image,main) VALUES(NULL,'$productcode','$filename','$main')"; mysql_query($entry) or die(mysql_error()); imagedestroy($src); imagedestroy($tmp); } } } Also, if anyone can write a better confirmation-checker (ie: that both images were uploaded successfully) that would be great! Right now, the confirmation message is based only off the thumb... Which kinda makes sense since the thumb is created from the first one, but I think there must be a better way! Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/50563-image-upload-and-resize-x2/ Share on other sites More sharing options...
triphis Posted May 8, 2007 Author Share Posted May 8, 2007 Should I be offering more information? lol I don't know what else I can tell you Quote Link to comment https://forums.phpfreaks.com/topic/50563-image-upload-and-resize-x2/#findComment-248605 Share on other sites More sharing options...
textbox Posted May 9, 2007 Share Posted May 9, 2007 I too would like to know how this works ! Quote Link to comment https://forums.phpfreaks.com/topic/50563-image-upload-and-resize-x2/#findComment-248634 Share on other sites More sharing options...
triphis Posted May 9, 2007 Author Share Posted May 9, 2007 See PHPexperts? This would be a good thing to help with *nudge* Quote Link to comment https://forums.phpfreaks.com/topic/50563-image-upload-and-resize-x2/#findComment-249093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.