redarrow Posted April 6, 2007 Share Posted April 6, 2007 advance thank you. my code seems to work but dosent change the uploded picture to the correct size can you help please cheers. <?php ob_start(); ?> <?php foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "images/$name"); // The file $filename = "images/$name"; // Set a maximum height and width $width = 200; $height = 200; // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output //imagejpeg($image_p, null, 100); } } ob_flush(); ?> <form action="" method="post" enctype="multipart/form-data"> <p>Pictures: <input type="file" name="pictures[]" /><br> <input type="file" name="pictures[]" /><br> <input type="file" name="pictures[]" /><br> <input type="submit" value="Send" /><br> </p> </form> Link to comment https://forums.phpfreaks.com/topic/45857-resize-image-problam-cheers/ Share on other sites More sharing options...
redarrow Posted April 6, 2007 Author Share Posted April 6, 2007 error as you can see i can not figure the loop out to get the images to show This part needs a loop but i tried please help cheers. imagejpeg($image_p, null, 100); imagejpeg(Resource id #3, null, 100); images/a.jpgimagejpeg(Resource id #7, null, 100); images/b.jpgimagejpeg(Resource id #11, null, 100); images/c.jpgimagejpeg(Resource id #15, null, 100); images/d.jpgimagejpeg(Resource id #19, null, 100); images/e.jpgimagejpeg(Resource id #23, null, 100); images/f.jpgimagejpeg(Resource id #27, null, 100); images/g.jpgimagejpeg(Resource id #31, null, 100); images/h.jpgimagejpeg(Resource id #35, null, 100); images/i.jpgimagejpeg(Resource id #39, null, 100); images/j.jpgimagejpeg(Resource id #43, null, 100); images/k.jpgimagejpeg(Resource id #47, null, 100); images/l.jpg current code <?php $x=array("a.jpg","b.jpg","c.jpg","d.jpg","e.jpg","f.jpg", "g.jpg","h.jpg","i.jpg","j.jpg","k.jpg","l.jpg"); foreach($x as $pic_name){ $filename = "images/$pic_name"; $width = 200; $height = 200; @header('Content-type: image/jpeg'); list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); echo"<table align='center'><tr> <td> imagejpeg($image_p, null, 100); </td></tr></table>"; echo $filename; } ?> Link to comment https://forums.phpfreaks.com/topic/45857-resize-image-problam-cheers/#findComment-222903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.