【问题标题】:Creating jpg thumb with php用 php 创建 jpg 拇指
【发布时间】:2011-02-06 23:41:09
【问题描述】:

我在从上传的图片创建缩略图时遇到问题,我的问题是

(i) 质量 (ii) 作物

http://welovethedesign.com.cluster.cwcs.co.uk/phpimages/large.jpg http://welovethedesign.com.cluster.cwcs.co.uk/phpimages/thumb.jpg

如果您看起来质量很差,并且裁剪是从顶部拍摄的,并且不是原始图像的大小调整,尽管尺寸意味着它是成比例的。

原件是 1600px1100px 高。

任何帮助将不胜感激。

 $thumb =
 $targetPath."Thumbs/".$fileName;

    $imgsize =
 getimagesize($targetFile);  $image =
 imagecreatefromjpeg($targetFile);
  $width = 200; //New width of image   
 $height = 138; //This maintains
 proportions

  $src_w = $imgsize[0]; $src_h =
 $imgsize[1];



 $thumbWidth = 200;  $thumbHeight =
 138; // Intended dimension of thumb

 // Beyond this point is simply code.

 $sourceImage =
 imagecreatefromjpeg($targetFile);
 $sourceWidth = imagesx($sourceImage);
 $sourceHeight = imagesy($sourceImage);

 $targetImage =
 imagecreate($thumbWidth,$thumbHeight);
 imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbWidth,imagesx($sourceImage),imagesy($sourceImage));

 //imagejpeg($targetImage,
 "$thumbPath/$thumbName");
 imagejpeg($targetImage, $thumb);

 chmod($thumb, 0755);

【问题讨论】:

  • 为了更好的使用质量imagecopyresampled(): php.net/imagecopyresampled
  • 质量和以前差不多,我现在主要做CF开发,但我好像记得有一种方法可以让你插入质量
  • 不要采取这种错误的方式,但您粘贴的示例代码是一团糟。您应该尝试去除绒毛,看看它是否解决了某些问题,至少如果没有,它会让其他人更容易立即看到问题。

标签: php image gd thumbnails


【解决方案1】:

每次创建缩略图时,图像的 DPI 都必须降低,因此不可能具有相同的质量,但是您可以检查 imagecreatetruecolor (http://in2.php.net/manual/en/function.imagecreatetruecolor.php) 以进行改进

【讨论】:

    【解决方案2】:

    您为图像高度使用了错误的变量。

    imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbWidth,imagesx($sourceImage),imagesy($sourceImage));
    

    应该是:

    imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbHeight,imagesx($sourceImage),imagesy($sourceImage));
    

    这应该会提高图像质量,但您应该使用 imagecopyresampled 来调整大小,并在保存到磁盘时使用 imagejpeg() 函数时使用 quality 参数。

    【讨论】:

    • @Ross,如果此答案解决了您的问题,请接受它作为正确答案
    • 您可能还想使用imagecopyresampled()。 resize 是“低质量”版本,如果您赶时间并且不关心调整大小的质量。重采样速度较慢,但​​效果更好。
    【解决方案3】:

    如果您使用Thumbnailer,您不会担心。

    $th=new Thumbnailer("your-photo.jpg");
    $th->thumbSymmetricWidth(200)->save("your-thumb.jpg");
    

    质量上乘。你也可以圆角。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-06
      • 2016-04-08
      相关资源
      最近更新 更多