ttt*_*bbb 1 php gd image filter
我想让我的图像更小,但生成的缩放图像具有锐利的边缘。
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);
}
Run Code Online (Sandbox Code Playgroud)
原来的:
我怎样才能用抗锯齿来做到这一点?
使用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);
}
Run Code Online (Sandbox Code Playgroud)