用于合并两个图标的PHP GD

用于合并两个图标的PHP GD,php,image-processing,gd,Php,Image Processing,Gd,我正在使用PHPGD库将两个图标合并为一个图标。但在其中一种情况下,较小的图标放在后面,较大的图标完全重叠,我需要小图标放在上面 这是我合并两个图标的代码, MergeIcons.php $firstIcon = $_GET['icon1']; $secondIcon = $_GET['icon2']; $image = imagecreatefrompng($firstIcon); $x1 = -1; $y1 = -1; $i = 0;

我正在使用PHPGD库将两个图标合并为一个图标。但在其中一种情况下,较小的图标放在后面,较大的图标完全重叠,我需要小图标放在上面

这是我合并两个图标的代码, 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;
     }
$firstIcon=$\u GET['icon1'];
$secondIcon=$_GET['icon2'];
$image=imagecreatefrompng($firstIcon);
$x1=-1;
$y1=-1;
$i=0;
$xCords=array();//用于保存非透明x跳线的阵列
$yCords=array();//用于保存非透明y形跳线的阵列
对于($x=0;$x 24;
$red=($pixelValue&0xFF0000)>>16;
$green=($pixelValue&0x00FF00)>>8;
$blue=($pixelValue&0x0000FF);
如果($alpha==127)
返回true;
其他的
返回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>';
echo'
  • ';
    在这种情况下,第二个图标是一个小图标,第一个图标是更大的图标,我希望在更大的图标上面有更小的图标(假设它像“把它带到前面”)

    有可能吗?

    “把它放在前面”-我想你想把一个图像作为一个图层放在另一个上面