[英]Image resize in PHP with anti-aliasing
I want to make my images smaller, but the resulting scaled images have sharp edges. 我想缩小图像,但是缩放后的图像边缘清晰。
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);
}
Original: 原版的:
How can I do it with anti-aliasing? 如何使用抗锯齿功能?
Use imagecopyresampled instead of imagecopyresized
. 使用imagecopyresampled而不是
imagecopyresized
。 It takes the same parameters and will resample the image instead of just altering the resolution. 它采用相同的参数,并且将重新采样图像,而不仅仅是改变分辨率。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.