PHP GD ライブラリを使用して、2 つのアイコンを 1 つにマージしています。しかし、小さいアイコンが後ろに入り、大きいアイコンが完全に重なる場合があります。小さいアイコンを上に配置する必要があります。
2 つのアイコンをマージするためのコードは、MergeIcons.php です。
$firstIcon = $_GET['icon1'];
$secondIcon = $_GET['icon2'];
$image = imagecreatefrompng($firstIcon);
$x1 = -1;
$y1 = -1;
$i = 0;
$xCords = array(); // Array to save non-transperent x cords
$yCords = array(); // Array to save non-transperent y cords
for($x=0;$x<16;$x++)
{
for($y=0;$y<16;$y++)
{
if (!transparent(imagecolorat($image, $x, $y)))
{
$xCords[$i] = $x;
$yCords[$i] = $y;
$i++;
}
}
}
$minX = min($xCords);
$minY = min($yCords);
$width = 16 - $minX;
$height = 16 - $minY;
$canvas = imagecreatetruecolor(16,16);
$col = imagecolorallocatealpha($canvas,0,0,0,127);
imagefilledrectangle($canvas,0,0,16,16,$col);
imagealphablending($canvas, true);
imagesavealpha($canvas, true);
imagefill($canvas, 0, 0, $col);
imagecopy($canvas, $image, 0, 0, $minX , $minY, $width, $height);
$dest = $canvas;
$src = imagecreatefrompng($secondIcon);
imagealphablending($dest, true);
imagesavealpha($dest, true);
$swidth = imagesx($src);
$sheight = imagesy($src);
imagecopy($dest, $src, 0,0,0,0,$swidth,$sheight);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
function transparent($pixelValue)
{
$alpha = ($pixelValue & 0x7F000000) >> 24;
$red = ($pixelValue & 0xFF0000) >> 16;
$green = ($pixelValue & 0x00FF00) >> 8;
$blue = ($pixelValue & 0x0000FF);
if($alpha == 127)
return true;
else
return false;
}
これが私がmergeicons.phpを呼び出す方法です
echo '<li><a href="MergeIcons.php?icon1='.$secondIconPath.'&icon2='.$firstIconPath.'" download="'.$IconNameQuery.'"><img src="MergeIcons.php?icon1='.$secondIconPath.'&icon2='.$firstIconPath.'"/></a></li>';
この場合、2 番目のアイコンは小さなアイコンで、最初のアイコンは大きなアイコンです。大きなアイコンの上に小さなアイコンを配置します (「前面に表示する」などと仮定します)。
それは可能ですか?