Jump to content

bad thumbnail quality


lukelee

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.