upendra470 Posted July 15, 2011 Share Posted July 15, 2011 I have been trying to compress a set of images which are entered through a form. But I am not able to compress the images. The images are uploaded in the 'gallery' folder but not in the 'thumbs' folder which stores the compressed images. Here is my code: $tsrc = "upload/thumbs/".$_FILES["image_id"]["name"][$j]; $imgfile = $_FILES["image_id"]["tmp_name"][$j]; move_uploaded_file($imgfile , "upload/gallery/" . $_FILES["image_id"]["name"][$j]); list($width,$height)=getimagesize($imgfile); echo $width; echo $height; $imgratio=$width/$height; if($imgratio>1) { $newwidth=$thumbsize; $newheight=$thumbsize/$imgratio; } else { $newheight=$thumbsize; $newwidth=$thumbsize*$imgratio; } $thumb=imagecreatetruecolor($newwidth,$newheight); // Making a new true color image $source=imagecreatefromjpeg($imgfile); // Now it will create a new image from the source imagecopyresampled($thumb,$source,0,0,0,0,$newwidth,$newheight,$width,$height); // Copy and resize the image imagejpeg($thumb,$tsrc,100); Please tell where i am wrong. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/242058-need-help-in-compressing-images/ Share on other sites More sharing options...
Psycho Posted July 15, 2011 Share Posted July 15, 2011 Your post title is misleading. Compression refers to reducing the size of the file such that the original remains unchanged or with a loss of fidelity. What you are asking about is resizing an image. Nothing in your code jumps out at me. Are you getting any errors? Quote Link to comment https://forums.phpfreaks.com/topic/242058-need-help-in-compressing-images/#findComment-1243089 Share on other sites More sharing options...
premiso Posted July 15, 2011 Share Posted July 15, 2011 You never write the generated thumb image to disk. Quote Link to comment https://forums.phpfreaks.com/topic/242058-need-help-in-compressing-images/#findComment-1243092 Share on other sites More sharing options...
PFMaBiSmAd Posted July 15, 2011 Share Posted July 15, 2011 move_uplaoded_file does what it's name indicates. It moves the uploaded file from the tmp/temp folder to the destination. Because you are reading the tmp/temp file - $_FILES["image_id"]["tmp_name"][$j] to resize it after you have executed the move_uplaoded_file statement, the file no longer exists and you would be getting a message something like the following (along with a few other related messages), if you had php's error reporting and display errors turned on - Warning: getimagesize(tmp\php1C.tmp) [function.getimagesize]: failed to open stream: No such file or directory in ... In your previous thread on this, you were apparently trying to use the destination where you moved the uploaded file to as the source for the resize logic. Why did you change to using the tmp/temp image? Quote Link to comment https://forums.phpfreaks.com/topic/242058-need-help-in-compressing-images/#findComment-1243095 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.