0
我使用PHP GD庫將兩個圖標合併爲一個。但在其中一種情況下,較小的圖標進入後面,較大的圖標完全重疊,我需要將小圖標放在最上面。用於合併兩個圖標的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>';
在這種情況下,第二個圖標是一個小圖標並且第一個圖標是較大的圖標,我想在較大的圖標頂部放置較小的圖標(假設它像「將它放在前面」一樣)。
這可能嗎?
http://stackoverflow.com/questions/5946679/adding-of-image-層層失敗-GD-PHP – zod