【问题标题】:PHP GD poor thumb qualityPHP GD 拇指质量差
【发布时间】:2011-07-21 20:40:31
【问题描述】:
            $tmp_im = imagecreatetruecolor($width, $height);
            $x = $this->getX();
            $y = $this->getY();

            $w = floor($resize_height * ($x / $y));
            $h = $resize_height;

            $this->tmp_im = imagecreatetruecolor($w, $h);

                            imagealphablending($this->tmp_im, false);
                            imagesavealpha($this->tmp_im, true);

                            imagecopyresampled($this->tmp_im, $this->im, 0, 0, 0, 0, $w, $h, $this->getX(), $this->getY());

            $this->im = $this->tmp_im;


            $hs = floor(($width - $this->getX())/2);
            $vs = floor(($height - $this->getY())/2);

            imagecopy($tmp_im, $this->im, $hs, $vs, 0, 0, $this->getX(), $this->getY());

            $this->im = $tmp_im;

结果是一个质量差的调整大小的图像,我做错了什么?我还尝试使用质量 = 100 的 imagejpeg

【问题讨论】:

  • 里面有一些奇怪的赋值,首先你创建 tmp_im,然后你创建 $this->tmp_im,然后你把 $this->tmp_im 赋值给 $this->im,然后你赋值$tmp_im 到 $this->im。那么你输出的是哪些东西?可能是错误的,还是不完整的?

标签: php resize gd


【解决方案1】:

使用imagecopytruecolor() 代替

imagecopy($tmp_im, $this->im, $hs, $vs, 0, 0, $this->getX(), $this->getY());

这是official PHP documentation page的通知:

由于调色板图像限制(255+1 色)存在问题。 重新采样或过滤图像通常需要超过 255 种颜色, 一种近似值用于计算新的重采样像素 和它的颜色。对于调色板图像,我们尝试分配一种新颜色,如果 失败了,我们选择最接近的(理论上)计算颜色。这是 并不总是最接近的视觉颜色。这可能会产生奇怪的结果, 像空白(或视觉空白)图像。要跳过这个问题,请 使用真彩色图像作为目标图像,例如由 imagecreatetruecolor().

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多