lukelee Posted December 13, 2008 Share Posted December 13, 2008 here is the code, the quality of the thumbnail is really bad, does anyone have any tips? <?php function makethumb($srcFile,$dstFile,$dstW,$dstH) { $data = GetImageSize($srcFile,&$info); switch ($data[2]) { case 1: $im = @ImageCreateFromGIF($srcFile); break; case 2: $im = @imagecreatefromjpeg($srcFile); break; case 3: $im = @ImageCreateFromPNG($srcFile); break; } $srcW=ImageSX($im); $srcH=ImageSY($im); $ni=ImageCreate($dstW,$dstH); ImageCopyResized($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH); ImageJpeg($ni,$dstFile); } $file1 = $_FILES['ufile']['name'][0]; $new_name1 = "upload/" . md5(uniqid(rand(), true)) . substr($file1, strrpos($file1, ".")); $filesize1=$_FILES['ufile']['size'][0]; if($filesize1>0) { $simage="n".date('Y-m-d-H-i-s',time()).".jpg";//$simage为生成缩略图文件名 move_uploaded_file($_FILES['ufile']['tmp_name'][0], $new_name1); $dst_image="upload/".$simage; makethumb($new_name1,$dst_image,'150','150'); } ?> Link to comment https://forums.phpfreaks.com/topic/136848-bad-thumbnail-quality/ Share on other sites More sharing options...
Caesar Posted December 13, 2008 Share Posted December 13, 2008 <?php ImageJpeg($ni,$dstFile, $quality); ?> http://us.php.net/manual/en/function.imagejpeg.php Link to comment https://forums.phpfreaks.com/topic/136848-bad-thumbnail-quality/#findComment-714761 Share on other sites More sharing options...
DarkWater Posted December 13, 2008 Share Posted December 13, 2008 Use imagecopyresampled() instead of imagecopyresized(). Link to comment https://forums.phpfreaks.com/topic/136848-bad-thumbnail-quality/#findComment-714768 Share on other sites More sharing options...
lukelee Posted December 14, 2008 Author Share Posted December 14, 2008 thanks for help, but still doesnt work, here is my new code: function makethumb($srcFile,$dstFile,$dstW,$dstH) { $data = GetImageSize($srcFile,&$info); switch ($data[2]) { case 1: $im = @ImageCreateFromGIF($srcFile); break; case 2: $im = @imagecreatefromjpeg($srcFile); break; case 3: $im = @ImageCreateFromPNG($srcFile); break; } $srcW=ImageSX($im); $srcH=ImageSY($im); $ni=ImageCreate($dstW,$dstH); Imagecopyresampled($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH); ImageJpeg($ni,$dstFile, 80); Link to comment https://forums.phpfreaks.com/topic/136848-bad-thumbnail-quality/#findComment-714972 Share on other sites More sharing options...
Caesar Posted December 15, 2008 Share Posted December 15, 2008 Try using 1-9 (1 through 9) when setting the image quality. It's been a while since I had to use image functions but if I remember, this is different when using ImageCopyResampled() (Which let's you set quality by %). Link to comment https://forums.phpfreaks.com/topic/136848-bad-thumbnail-quality/#findComment-715982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.