rabesh Posted June 9, 2011 Share Posted June 9, 2011 I write code for image resize but the following errors occurs... i am new for image resizing in php Warning: imagecreatefromjpeg(gallery/show2.gifshow2.gif) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\wamp\www\gallery for kokine\test4gallery.php on line 40 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\wamp\www\gallery for kokine\test4gallery.php on line 41 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\wamp\www\gallery for kokine\test4gallery.php on line 42 Warning: Division by zero in C:\wamp\www\gallery for kokine\test4gallery.php on line 48 Warning: imagecreate() [function.imagecreate]: Invalid image dimensions in C:\wamp\www\gallery for kokine\test4gallery.php on line 52 Warning: imagetruecolortopalette() expects parameter 1 to be resource, boolean given in C:\wamp\www\gallery for kokine\test4gallery.php on line 53 Warning: imagecolorstotal() expects parameter 1 to be resource, boolean given in C:\wamp\www\gallery for kokine\test4gallery.php on line 54 Warning: imagecopyresized() expects parameter 1 to be resource, boolean given in C:\wamp\www\gallery for kokine\test4gallery.php on line 59 Warning: imagejpeg() expects parameter 1 to be resource, boolean given in C:\wamp\www\gallery for kokine\test4gallery.php on line 60 Warning: imagedestroy() expects parameter 1 to be resource, boolean given in C:\wamp\www\gallery for kokine\test4gallery.php on line 61 Warning: imagedestroy() expects parameter 1 to be resource, boolean given in C:\wamp\www\gallery for kokine\test4gallery.php on line 62 my code is <?php include('include/connection.php'); if (isset ($_POST['submitted'])) { $filename=$_FILES['image']['name']; $des=$_POST['des']; $cap=$_POST['caption']; $status=$_POST['status']; $category=0; $image_dir = "gallery/".$filename; if(!is_dir("gallery")): mkdir("gallery"); endif; $tdir = "gallery/thumbs/"; // Path To Thumbnails Directory $twidth = "125"; // Maximum Width For Thumbnail Images $theight = "100"; // Maximum Height For Thumbnail Images if(move_uploaded_file($_FILES['image']['tmp_name'],$image_dir)) { list($w,$h,$t) = getimagesize($image_dir); switch($t) { case 1: $ext = ".png"; break; case 2: $ext = ".jpg"; break; case 3: $ext = ".gif"; break; default: $ext = ".jpg"; } $simg = imagecreatefromjpeg("$image_dir" . $filename); // Make A New Temporary Image To Create The Thumbanil From $currwidth = imagesx($simg); // Current Image Width $currheight = imagesy($simg); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $twidth / $currheight; // Length Ratio For Width $newheight = $theight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $twidth / $currwidth; // Length Ratio For Height $newwidth = $twidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It) imagejpeg($dimg, "$tdir" . $filename); // Saving The Image imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image mysql_query('INSERT INTO tbl_gallery(`title` ,`description` ,`name`,`category_name`,`status`)VALUES ("'.$cap.'", "'.$des.'", "'.$filename.'","'.$category.'", "'.$status.'")'); $id = mysql_insert_id(); $new_image = "gallery/".$id.$ext; //echo "update tbl_gallery set image_name='".$new_image."' where id = ".$id; //die("here"); $res = mysql_query("update tbl_gallery set name='".$new_image."' where id = ".$id) or die(mysql_error()); rename($image_dir,$new_image); echo 'upload successful'; //$img=getimagesize('upload/'.$filename); // echo $width.$height.$type.$attr; // print_r($img); } } ?> <link rel="stylesheet" type="text/css" href="css/style.css"> <body> <!--<table > <form method="post" enctype="multipart/form-data" > <tr> <td>Caption</td> <td><input type="text" name="caption" /></td> </tr> <tr> <td>Description</td> <td><textarea name="des" rows="15" cols="15"></textarea></td> </tr> <tr> <td>Image Name</td><td><input type="file" name="image" /></td> </tr> <tr> <td>Status:</td> <td> <input type="radio" name="status" value="1" checked>Show<input type="radio" name="status" value="0">Hide</td> </tr> <tr><td><input type="submit" name="submitted" value="upload" /></td></tr> </form> </table>--> <div class="form_box"> <form method="post" enctype="multipart/form-data" > <div class="upload"> <label>Caption:</label> <input type="text" name="caption" /> </div> <div class="upload"> <label>Description:</label> <textarea name="des" rows="15" cols="15"></textarea> </div> <div class="upload"> <label>Browse Image File:</label> <input type="file" name="image" /> </div> <!--<div class="upload"> <label>Please Select the Catagory:</label> <select> <option value="1">Boutique Saree</option> <option value="2">Simple Saree</option> <option value="3">Kurtha Salwar</option> <option value="4">others</option> </select> </div>--> <div class="upload"> <label>Status:</label> <input type="radio" name="status" value="1" checked>Show<input type="radio" name="status" value="0">Hide </div> <div class="upload"><input type="submit" name="submitted" value="upload" /> </div></form></div> <div><a href="index.php">Go Back</a></div> any body can solve my problem MOD EDIT: code tags added. Link to comment Share on other sites More sharing options...
WebStyles Posted June 9, 2011 Share Posted June 9, 2011 can't really go through all of your code right now, but the first error should give you a hint. Warning: imagecreatefromjpeg(gallery/show2.gifshow2.gif) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\wamp\www\gallery for kokine\test4gallery.php on line 40 "No such file in directory" If the function cannot find the image, it's probably not being uploaded correctly or has a different path or name. After uploading, check the upload folder to see if it's there. Then check that the filename and path match the ones you wanted. If not, there's a problem either uploading, or moving the uploaded file. Hope this helps Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 9, 2011 Share Posted June 9, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Link to comment Share on other sites More sharing options...
mohsened Posted June 10, 2012 Share Posted June 10, 2012 Hey dude.. you have a very small problem in line 40 please replace: $simg = imagecreatefromjpeg("$image_dir" . $filename); with $simg = imagecreatefromjpeg("$image_dir"); THAT'S IT Link to comment Share on other sites More sharing options...
insidus Posted June 10, 2012 Share Posted June 10, 2012 I dunno if this will help you, but i was having a similar problem the other day.. i found this site and i kinda figured it out http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/ Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 10, 2012 Share Posted June 10, 2012 @ both mohsened and insidus, This thread is over one year old. I'm pretty sure the OP discovered the problem in his code. Link to comment Share on other sites More sharing options...
Recommended Posts