缩放图像(放大)并使用GD库添加抗锯齿

时间:2018-07-26 09:53:53

标签: php image gd

我有一段代码将图像作为输入并进行调整大小(放大,使其更大)。输入图像不包含任何抗锯齿,这意味着它具有清晰的边框和角。 我希望此缩放过程可以添加抗锯齿,使其具有平滑的边框和边缘,就像某些图形程序一样(例如paint.NET,如果我将图像放大,则会自动添加抗锯齿)。 我该怎么办?

这是我的代码

private function resize($source_path, $dest_path, $dest_w, $dest_h)
{
    $source = imagecreatefrompng($source_path);
    $source_w = imagesx($source);
    $source_h = imagesy($source);

    $output = imagecreatetruecolor($dest_w, $dest_h);
    imagealphablending($output, false);
    $transparent = imagecolorallocatealpha($output, 0, 0, 0, 127);
    imagefilledrectangle($output, 0, 0, $dest_w, $dest_h, $transparent);
    imagesavealpha($output, true);

    if (imagecopyresampled($output, $source, 0, 0, 0, 0, $dest_w, $dest_h, $source_w, $source_h)) {
        if (imagepng($output, $dest_path)) {
            return true;
        }
    }

    return false;
}

谢谢您的帮助。

编辑:我试图添加插值

imagesetinterpolation($output,IMG_BICUBIC);

但没有任何改变。

0 个答案:

没有答案