You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP GD库WebP图片拼接边缘块状模糊问题求助

WebP图片拼接后边缘画质劣化问题

我从Stack Overflow找到一段图片拼接代码,适配为WebP格式后可正常运行,但输出图片边缘画质极低,呈现块状模糊。原图片为带透明通道的WebP格式,我尝试过多种格式和函数仍未解决,恳请帮助。

以下是我使用的代码:

$images = array(
    "image1.webp",
    "image2.webp"
);
$number_of_images = count($images);

$priority = "columns"; // also "rows"

if ($priority == "rows") {
  $rows = 3;
  $columns = $number_of_images/$rows;
  $columns = (int) $columns; // typecast to int. and makes sure grid is even
} elseif ($priority == "columns") {
  $columns = 1;
  $rows = $number_of_images/$columns;
  $rows = (int) $rows; // typecast to int. and makes sure grid is even
}
$width = 1000; // image width
$height = 406; // image height

$background = imagecreatetruecolor(($width*$columns), ($height*$rows)); // setting canvas size

$output_image = $background;

// Creating image objects
$image_objects = array();
for($i = 0; $i < ($rows * $columns); $i++){
  $image_objects[$i] = imagecreatefromwebp($images[$i]);
}

// Merge Images
$step = 0;
for($x = 0; $x < $columns; $x++) {
  for($y = 0; $y < $rows; $y++) {
    imagecopymerge($output_image, $image_objects[$step], ($width * $x), ($height * $y), 0, 0, $width, $height, 100);
    $step++; // steps through the $image_objects array
  }
}

imagewebp($output_image, "test.webp");
imagedestroy($output_image);

print "<div><img src='test.webp' /></div>";

输出效果:
输出图片效果

内容的提问来源于stack exchange,提问作者Simon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 15:00:18