Guest Posted November 21, 2006 Share Posted November 21, 2006 When i upload an image that is to big the picture gets very blury it does resize it though. Please help.[code]define ( 'UPLOAD_PATH', 'Uploads/Houses/' );define ( 'MAX_SIZE', '100000' ); // define the max single file size (bytes)$allow = array ( 'png', 'gif', 'jpg' ); // allowed types$max_width = 640; // max width (resize width)$max_height = 480; // max height (resize height)$max_twidth = 100; // max width (resize width)$max_theight = 100; // max height (resize height)$save = false; // save original upload image (bool true or false)$quality = 100; // the quality for (jpg) images//upload thumbnailif ( is_uploaded_file ( $_FILES['image']['tmp_name']['0'] ) ) { $fs = filesize ( $_FILES['image']['tmp_name']['0'] ); // file size test (size test) if ( $fs > 10 && $fs <= MAX_SIZE ) { $fn = strtolower ( $_FILES['image']['name']['0'] ); $fe = substr ( $fn, ( strrpos ( $fn, '.' ) + 1 ) ); // is it a valid image type (extension test) if ( in_array ( $fe, $allow ) ) { // is it a valid image type (image file test) if ( ( $image = getimagesize ( $_FILES['image']['tmp_name']['0'] ) ) !== false ) { // get the width and height of the upload image list ( $width, $height ) = $image; // load the upload image into the image resource switch ( $fe ) { case 'gif' : $old = imagecreatefromgif ( $_FILES['image']['tmp_name']['0'] ); break; case 'jpg' : $old = imagecreatefromjpeg ( $_FILES['image']['tmp_name']['0'] ); break; case 'png' : $old = imagecreatefrompng ( $_FILES['image1']['tmp_name']['0'] ); break; } // create the original image ratio $original_ratio = ( $width / $height ); // figure what controls the resize (width or height) if ( $max_twidth / $max_theight > $original_ratio ) { $max_twidth = ( $max_theight * $original_ratio ); } else { $max_theight = ( $max_twidth / $original_ratio ); } // create a new image resource the size of the new ratio $new = imagecreatetruecolor ( $max_twidth, $max_theight ); //copy original to the resized image and resample it imagecopyresampled ( $new, $old, 0, 0, 0, 0, $max_twidth, $max_theight, $width, $height ); // save the new thumbnail image switch ( $fe ) { case 'gif' : imagegif ( $new, UPLOAD_PATH . $imagename . "-1-t." . $fe ); break; case 'jpg' : imagejpeg ( $new, UPLOAD_PATH . $imagename . "-1-t." . $fe, $quality); break; case 'png' : imagepng ( $new, UPLOAD_PATH . $imagename . "-1-t." . $fe ); break; } // kill the image resources imagedestroy ( $old ); imagedestroy ( $new ); // are we saving the orignal if ( $save ) { @move_uploaded_file ( $_FILES['image']['tmp_name']['0'], UPLOAD_PATH . $sn ); } $out = "Image 1 uploaded successfully"; $sqlthumb1 = UPLOAD_PATH . $imagename . "-1-t." . $fe; } } } }// end of thumbnail[/code] Link to comment https://forums.phpfreaks.com/topic/28021-image-resize-blury/ Share on other sites More sharing options...
Caesar Posted November 21, 2006 Share Posted November 21, 2006 Too lazy to look through your code since you have not added the longhand php tag which would have color coded everything.Anyway, you can define the image quality % when using GD for sampling/copying an image. Link to comment https://forums.phpfreaks.com/topic/28021-image-resize-blury/#findComment-128179 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.