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
. 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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.