gpt4 book ai didi

php - 使用抗锯齿在 PHP 中调整图像大小

转载 作者:行者123 更新时间:2023-12-02 17:21:28 24 4
gpt4 key购买 nike

我想让我的图片变小,但生成的缩放后的图片边缘很锐利。

 foreach ($images as $image){
$filename=$initPath.$sku.'/'.$srcFolder.'/'.$image;
//$percent=0.5;
list($width, $height) = getimagesize($filename);
//$newwidth = $width * $percent;
//$newheight = $height * $percent;
$fh = fopen($initPath.$sku.'/'.$distFolder.'/'.$image, 'w');
fclose($fh);
$wtf= realpath($initPath.$sku.'/'.$distFolder.'/'.$image);

// загрузка
$thumb = imagecreatetruecolor(200, 200);
imagesetinterpolation($thumb,IMG_BICUBIC);
imagealphablending($thumb, false);
imagesavealpha($thumb,true);
$transparent = imagecolorallocatealpha($thumb, 255, 255, 255, 127);

$source = imagecreatefrompng($filename);
// изменение размера
imagecopyresized($thumb, $source, 0, 0, 0, 0, 200, 200, $width, $height);
// вывод
imagepng($thumb,$wtf,1);

}

原文:

enter image description here

结果: enter image description here

如何使用抗锯齿来做到这一点?

最佳答案

使用imagecopyresampled而不是 imagecopyresized。它采用相同的参数并将对图像重新采样,而不仅仅是改变分辨率。

foreach ($images as $image){
$filename=$initPath.$sku.'/'.$srcFolder.'/'.$image;
//$percent=0.5;
list($width, $height) = getimagesize($filename);
//$newwidth = $width * $percent;
//$newheight = $height * $percent;
$fh = fopen($initPath.$sku.'/'.$distFolder.'/'.$image, 'w');
fclose($fh);
$wtf= realpath($initPath.$sku.'/'.$distFolder.'/'.$image);

// загрузка
$thumb = imagecreatetruecolor(200, 200);
imagesetinterpolation($thumb,IMG_BICUBIC);
imagealphablending($thumb, false);
imagesavealpha($thumb,true);
$transparent = imagecolorallocatealpha($thumb, 255, 255, 255, 127);

$source = imagecreatefrompng($filename);
// изменение размера
imagecopyresampled($thumb, $source, 0, 0, 0, 0, 200, 200, $width, $height);
// вывод
imagepng($thumb,$wtf,1);

}

关于php - 使用抗锯齿在 PHP 中调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42346850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com