AndieB Posted June 7, 2007 Share Posted June 7, 2007 Hi all! I have used the below script to resize images, but every picture uploaded seems to loss quality and I can not figure out why? Perhaps anyone who reads this can help me out! // CHECK WHAT FORMAT THE PICTURE IS, LANDSCAPE OR PORTRAIT $fileSize = getimagesize($uploaddir . $tmpnewfilename); $new_file_width = $fileSize['width']; $new_file_height = $fileSize['height']; if ($new_file_height > $new_file_width) { $new_file_new_width = 427; $new_file_new_height = 307; $destimg = ImageCreateTrueColor( $new_file_new_width, $new_file_new_height ) or die( "Problem In Creating image" ); $srcimg = ImageCreateFromJPEG( $uploaddir.$tmpnewfilename ) or die( "Problem In opening Source Image" ); ImageCopyResampled( $destimg, $srcimg, 0, 0, 0, 0, $new_file_new_width, $new_file_new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing"); ImageJPEG($destimg,$uploaddir.$newfilename) or die("Problem In saving"); unlink($uploaddir . $tmpnewfilename); } else { $new_file_new_width = 640; $new_file_new_height = 427; $destimg=ImageCreateTrueColor($new_file_new_width,$new_file_new_height) or die("Problem In Creating image"); $srcimg=ImageCreateFromJPEG($uploaddir.$tmpnewfilename) or die("Problem In opening Source Image"); ImageCopyResampled($destimg,$srcimg,0,0,0,0,$new_file_new_width,$new_file_new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing"); ImageJPEG($destimg,$uploaddir.$newfilename) or die("Problem In saving"); unlink($uploaddir . $tmpnewfilename); } Does the DPI (Dots Per Inch) change in the script above? I would very much appreciate help! Sincerely, Andreas Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 7, 2007 Share Posted June 7, 2007 That's what images do - you are taking the same data and trying to place it all in a smaller (or larger) visual space. this means that some interpolation will occur between pixels to try and replicate the colours. The GD Library is not as sophisticated as graphic apps such as photoshop - they have sophistcaed algorithms and can far better utilise vector based algorithms to maintain the 'quality' of an image. Quote Link to comment Share on other sites More sharing options...
AndieB Posted June 7, 2007 Author Share Posted June 7, 2007 So, I understand from your feedback that there are no hints or tips regarding maintaining better quality? Thanks for you answer! Sincerely, Andreas Quote Link to comment 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.