richrock Posted February 15, 2009 Share Posted February 15, 2009 Hi all, Been making myself really wound up with this one. I need to upload three images, and I've created a loop to do so. Not a problem so far. I've opted to use php's built-in functions as they are far superior to another open source one I got referred to... Now my problem is this - I can either create the black jpg in the new filename I need, or copy the image without it resizing. I've checked all the manuals for the functions on php.net (where I got the source code from) but it's not working - can anyone see if I'm missing a trick? // Init the image counter $img_number = 0; //echo "Img Num: ".$img_number."<br />"; //Process_Image($auct_id, $userid, $tmp_name, $name, $img_number); // Upload the images - redeveloped to match the existing auction system // Here we upload our images, and then set foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { //Check if GD extension is loaded if (!extension_loaded('gd') && !extension_loaded('gd2')) { trigger_error("GD is not loaded", E_USER_WARNING); return false; } $th_width = '62'; $th_height = '93'; $re_width = '132'; $re_height = '198'; $mi_width = '320'; $mi_height = '480'; $lg_width = '892'; $lg_height = '1338'; $or_width = '892'; $or_height = '1338'; $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; echo "TMP Name: ".$tmp_name." - ".$img_number."<br />"; $name = $_FILES["pictures"]["name"][$key]; $newname = $rec_num."-".$line_num."-".$img_number.".jpg"; echo "New filename: ".$newname."<br />"; $path = AUCTION_PICTURES_PATH; echo "PATH: ".$path."<br />"; move_uploaded_file($tmp_name,$path.$newname); //copy($tmp_name,$path.$newname); echo $tmp_name; echo "<br />".$path; echo "moved to: ".$path.$newname."<br />"; // Process the file $filename = $newname; echo "<br />Filename = ".$filename."<br />Newname = ".$newname."<br />"; $orig_path = $path."orig_".$newname; $orig_name = "orig_".$newname; $thumb_path = $path."thumb_".$newname; $resize_path = $path."resize_".$newname; $middle_path = $path."middle_".$newname; //echo $resize_path."<br />"; // Content type //header('Content-type: image/jpeg'); // if this is on it creates a header error, despite being at the top of the file. //copy($path.$newname,$path); copy($path.$newname,$orig_path); copy($path.$newname,$thumb_path); copy($path.$newname,$resize_path); copy($path.$newname,$middle_path); //list($width,$height) = getimagesize($path.$newname); list($t_width, $t_height) = getimagesize($path."thumb_".$newname); $image_p = imagecreatetruecolor($th_width, $th_height); $image = imagecreatefromjpeg($path.$newname); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $th_width, $th_height, $t_width, $t_height); imagejpeg($image_p, $path."thumb_".$newname, 90); list($r_width, $r_height) = getimagesize($path."resize_".$newname); $image_p = imagecreatetruecolor($re_width, $re_height); $image = imagecreatefromjpeg($path.$newname); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $re_width, $re_height, $r_width, $r_height); imagejpeg($image_p, $path."resize_".$newname, 90); list($m_width, $m_height) = getimagesize($path."middle_".$newname); $image_p = imagecreatetruecolor($mi_width, $mi_height); $image = imagecreatefromjpeg($newname); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $mi_width, $mi_height, $m_width, $m_height); imagejpeg($image_p,$newname, 80); list($width, $height) = getimagesize($newname); echo "got image size<br />"; $image_p = imagecreatetruecolor($or_width, $or_height); echo "got image_p<br />"; $image = imagecreatefromjpeg($newname); echo "got imagecreatefromjpeg<br />"; imagecopyresampled($image_p, $image, 0, 0, 0, 0, $or_width, $or_height, $width, $height); //imagecopyresized($image_p, $image, 0, 0, 0, 0, $or_width, $or_height, $width, $height); // tried this - doesn't work either echo "got imagecopyresampled<br />"; imagejpeg($image_p,"orig_".$newname, 80); echo "got imagejpeg"; $img_number++; // Insert the image into the DB /*$put_images = "INSERT INTO jos_bid_pictures "; $put_images .= "(`id_offer`,`userid`,`picture`) "; $put_images .= "VALUES "; $put_images .= "('".$auct_id."', "; $put_images .= "'".$usrid."', "; $put_images .= "'".$newname."')"; $rput_images = mysql_query($put_images) or die('Secondary image upload error at: ' . mysql_errno() . mysql_error());*/ // will activate this when working... //echo $put_images; } // Endif } as you can see I need to resize the same image to 5 different sizes, due to thumbnails/original images being displayed on various pages with different size constraints. Any ideas/suggestions welcom. Link to comment https://forums.phpfreaks.com/topic/145298-imagecreate-in-loop-either-creating-black-image-or-not-resizing/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.