How can I resize an uploaded image in PHP -


this question has answer here:

i using code users can upload images site

$allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg','.jpg','.png','.bif','.gif','.jpeg'); // these types of file pass validation. $max_filesize = 524288; //  filesize in bytes (currently 0.5mb). $uploadpath = "/home/path/to/file/files/avatars/$_session[user]"; $posted9 = hash('md5',$_session["user"]).$ext; /* not security mind you. */ // upload file specified path.         $f = file_put_contents(             $upload_path . $posted9,             file_get_contents('php://input')             );         if($f)     $m="avatar updated<br/>"; // worked.   else      $m="there error during file upload.  please try again."; // failed :(. 

however, when images rezised fit inside comments on website, become distorted , lose quality.

how using php can resize images quality maintained?

<?php  // url of file $url = "/homepages/0/d502303335/htdocs/foo.jpg";  // set maximum height , width, used ones on picture $width = 49; $height = 47;   // new dimensions list($width_orig, $height_orig) = getimagesize($url);  // resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($url); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);  // output, can use url, in case overwrite picture imagejpeg($image_p, $url);  ?> 
here's result: http://www.filmgratuiti.org/varie/cenbqhxmd90q2.jpg
more better your's

so after have uploaded file run code , go


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -