我正在使用 PHP GD 库将两个图标合并为一个。但是在其中一种情况下,较小的图标进入后面并且较大的图标完全重叠,我需要小图标位于顶部。
这是我合并两个图标的代码 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>';
在这种情况下,第二个图标是一个小图标,第一个图标是大图标,我想要在大图标之上的小图标(假设它像“把它带到前面”)。
那可能吗?