PHP GD用于合并两个图标

I am using PHP GD library to merge two icons into one. But in one of the cases the smaller icon goes into back and bigger icon overlaps it completely, I need the small icon to be on top.

Here is my code for merging two icons, 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;
     }

Here is how I call the mergeicons.php

echo '<li><a href="MergeIcons.php?icon1='.$secondIconPath.'&icon2='.$firstIconPath.'" download="'.$IconNameQuery.'"><img src="MergeIcons.php?icon1='.$secondIconPath.'&icon2='.$firstIconPath.'"/></a></li>';

In this case, second icon is a small icon and first icon is bigger icon, I want smaller icon on top of bigger icon ( assume its like "Bring it to Front ").

Is that possible?

"bring it front " - i think you want to put one image as a layer on the other

http://phpimageworkshop.com/