PHP图像重采样问题

时间:2011-03-11 07:15:43

标签: php gd

当我重新采样jpg以便在图像周围绘制边框时,图像的质量大大降低,并且获得了极低质量的jpeg。 enter image description here

这是我的代码:

function addBorderpng($add,$bdr=0,$color='#000000'){
                $arr = explode('.', $add);
                $extension = strtolower(end($arr));
                $border=$bdr;

$im=imagecreatefromjpeg($add);

                $width=imagesx($im);
                $height=imagesy($im);
                $img_adj_width=$width+(2*$border);
                $img_adj_height=$height+(2*$border);
                $newimage=imagecreatetruecolor($img_adj_width,$img_adj_height);

                imageantialias($newimage, true);
                $color_gb_temp =HexToRGB($color);
                $border_color = imagecolorallocate($newimage, $color_gb_temp['r'], $color_gb_temp['g'], $color_gb_temp['b']);
                imagefilledrectangle($newimage,0,0,$img_adj_width,$img_adj_height,$border_color);
                imagealphablending($newimage, true);
                imageantialias($newimage, true);
                     imagecopyresized($newimage,$im,$border,$border,0,0,$width,$height,$width,$height);
                    imagejpeg($newimage,$add,9);
            }

2 个答案:

答案 0 :(得分:5)

imagejpeg的最后一个参数是质量。

  

质量是可选的,范围从0(最差质量,较小文件)到100(最佳质量,最大文件)。默认值是默认的IJG质量值(约75)。

您将其设置为9,因此质量较差。

答案 1 :(得分:1)

此外,您可以尝试使用“imagecopyresampled”代替“imagecopyresized”来处理插值PHP imagecopyresampled