r00tk1LL Posted August 3, 2007 Share Posted August 3, 2007 I found a script that is supposed to upload and resize images but I am getting allot of warnings. I think I need to include a file, not really sure what to do. Found script here http://www.phpfreaks.com/forums/index.php/topic,142984.0.html Heres the code: <?php // Get the details of "imagefile" $filename = $_FILES['imagefile']['name']; $temporary_name = $_FILES['imagefile']['tmp_name']; $mimetype = $_FILES['imagefile']['type']; $filesize = $_FILES['imagefile']['size']; //Open the image using the imagecreatefrom..() command based on the MIME type. switch($mimetype) { case "image/jpg": case "image/jpeg": $i = imagecreatefromjpeg($temporary_name); break; case "image/gif": $i = imagecreatefromgif($temporary_name); break; case "image/png": $i = imagecreatefrompng($temporary_name); break; } //Delete the uploaded file unlink($temporary_name); //Save a copy of the original imagejpeg($i,"images/uploadedfile.jpg",80); //Specify the size of the thumbnail $dest_x = 150; $dest_y = 150; //Is the original bigger than the thumbnail dimensions? if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) { //Is the width of the original bigger than the height? if (imagesx($i) >= imagesy($i)) { $thumb_x = $dest_x; $thumb_y = imagesy($i)*($dest_x/imagesx($i)); } else { $thumb_x = imagesx($i)*($dest_y/imagesy($i)); $thumb_y = $dest_y; } } else { //Using the original dimensions $thumb_x = imagesx($i); $thumb_y = imagesy($i); } //Generate a new image at the size of the thumbnail $thumb = imagecreatetruecolor($thumb_x,$thumb_y); //Copy the original image data to it using resampling imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i)); //Save the thumbnail imagejpeg($thumb, "images/thumbnail.jpg", 80); ?> Heres the crazy output: Warning: unlink(): No such file or directory in /path/thumb.php on line 24 Warning: imagejpeg(): supplied argument is not a valid Image resource in /path/thumb.php on line 27 Warning: imagesx(): supplied argument is not a valid Image resource in /path/thumb.php on line 34 Warning: imagesy(): supplied argument is not a valid Image resource in /path/thumb.php on line 34 Warning: imagesx(): supplied argument is not a valid Image resource in /path/thumb.php on line 45 Warning: imagesy(): supplied argument is not a valid Image resource in /path/thumb.php on line 46 Warning: imagecreatetruecolor(): Invalid image dimensions in /path/thumb.php on line 50 Warning: imagesx(): supplied argument is not a valid Image resource in /path/thumb.php on line 53 Warning: imagesy(): supplied argument is not a valid Image resource in /path/thumb.php on line 53 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /path/thumb.php on line 53 Warning: imagejpeg(): supplied argument is not a valid Image resource in /path/thumb.php on line 56 Tell me what I'm missing here, Thanks Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/ Share on other sites More sharing options...
akitchin Posted August 3, 2007 Share Posted August 3, 2007 looks like your $_FILES array isn't receiving any info, as the switch() isn't even executing. try this at the top: print_r($_FILES); could be that you haven't named your file input correctly, or forgot to change the encoding attribute. Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315105 Share on other sites More sharing options...
r00tk1LL Posted August 3, 2007 Author Share Posted August 3, 2007 It says: Array ( [fupload] => Array ( [name] => Water lilies.jpg [type] => image/jpeg [tmp_name] => /tmp/phpiR2Xlm [error] => 0 [size] => 83794 ) ) And what does "print_r" mean?? Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315111 Share on other sites More sharing options...
akitchin Posted August 3, 2007 Share Posted August 3, 2007 print_r() is a function that will take an array as its argument, and output all of its data (along with its structure). it's handy for debugging array values. your problem is that you've named the file input "fupload", while the script itself is looking for "imagefile." change one or the other to match and see how it works. Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315115 Share on other sites More sharing options...
r00tk1LL Posted August 3, 2007 Author Share Posted August 3, 2007 Cool it worked, Thanks. Let me ask you this, would it be possible to make the thumbnail 100px wide and the height automatically adjust to the right proportion? Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315123 Share on other sites More sharing options...
akitchin Posted August 3, 2007 Share Posted August 3, 2007 if you set the $dest_width to 100, and $dest_height to something enormous (assuming you want ONLY the width to reduce). Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315124 Share on other sites More sharing options...
r00tk1LL Posted August 3, 2007 Author Share Posted August 3, 2007 Well I would want to keep it proportional.. I noticed that when you do something like: <img width=100></img> In HTML, the image will adjust down properly... Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315129 Share on other sites More sharing options...
akitchin Posted August 3, 2007 Share Posted August 3, 2007 this script takes care of proportioning the image appropriately. if you specify width and heights of 150, it will take the offending dimension, scale it down to 150, and scale the other dimension to be proportional to the new 150. Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315135 Share on other sites More sharing options...
r00tk1LL Posted August 3, 2007 Author Share Posted August 3, 2007 Here's the situation Im in: I have an HTML template that pulls a users information from a DB, then formats a nice homepage for them. When their pictures are wider than 100px, it stretches the page and ruins the way the template looks. I would like to make every thumbnail no wider than that size to stop this, but not distort the image. You see what I'm getting at? So you're saying that if I have a pic 200px wide and 400px tall, it will reduce it to 100px wide and 200px tall (the right proportion) if I say: width=100 height=100 Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315137 Share on other sites More sharing options...
akitchin Posted August 3, 2007 Share Posted August 3, 2007 then specify 100 as the $dest_x in the script you're using. this will resize all thumbnails to being no more than 100, and will resize the vertical size proportionally. Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315139 Share on other sites More sharing options...
r00tk1LL Posted August 3, 2007 Author Share Posted August 3, 2007 Have a look at these sample pictures: original http://www.mynorthtexas.com/mypages/final/create/images/uploadedfile.jpg Thumbnail http://www.mynorthtexas.com/mypages/final/create/images/thumbnail.jpg I specified $dest_x = 100; $dest_y = 100; but I just want the width to be 100 Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315144 Share on other sites More sharing options...
akitchin Posted August 3, 2007 Share Posted August 3, 2007 if you set the $dest_width to 100, and $dest_height to something enormous (assuming you want ONLY the width to reduce). not sure if i said it clearly enough, so: $dest_x = 100; $dest_y = 1000000000; Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315145 Share on other sites More sharing options...
r00tk1LL Posted August 3, 2007 Author Share Posted August 3, 2007 This is what I got with that: Fatal error: Possible integer overflow in memory allocation (4 * 1000000000 + 0) in /path/thumb.php on line 49 Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315148 Share on other sites More sharing options...
akitchin Posted August 3, 2007 Share Posted August 3, 2007 drop a few 0's then. or you could remove the nested if()s altogether: //Specify the size of the thumbnail $dest_x = 100; //Is the original bigger than the thumbnail dimensions? if (imagesx($i) > $dest_x) { $thumb_x = $dest_x; $thumb_y = imagesy($i)*($dest_x/imagesx($i)); } else { //Using the original dimensions $thumb_x = imagesx($i); $thumb_y = imagesy($i); } if you're going to use a PHP script or want to edit it, you should at least do your best to understand what exactly it's doing. Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315149 Share on other sites More sharing options...
r00tk1LL Posted August 3, 2007 Author Share Posted August 3, 2007 Yeah I'm pretty new to coding all together, but I'm starting to grasp the concepts. The script seems to be doing what I want now, but I'll leave this thread unsolved for a little while longer until I know for sure. Check those links a couple of posts back and you'll see what I was looking for. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315152 Share on other sites More sharing options...
r00tk1LL Posted August 3, 2007 Author Share Posted August 3, 2007 Everything is working fine, topic solved Quote Link to comment https://forums.phpfreaks.com/topic/63225-solved-help-with-image-upload-and-resize-script/#findComment-315167 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.