我试图将图像的背景颜色从白色更改为透明,然后将其作为遮罩放在另一图像上。 (不能是透明不已,因为另一部分是用来作为一个面具戴在另一个图像)...层乐趣:)PHP将图像颜色更改为透明,然后用作蒙板
全码:
<?
include '../includes/db.php';
include '../includes/checks.php';
$type = $_GET['t']; //shirt | shorts
$style = $_GET['s'];
$z = $_GET['z']; // home | away
$a = $_GET['a'];
$b = $_GET['b'];
$aR = hexdec($a['0'].$a['1']);
$aG = hexdec($a['2'].$a['3']);
$aB = hexdec($a['4'].$a['5']);
$bR = hexdec($b['0'].$b['1']);
$bG = hexdec($b['2'].$b['3']);
$bB = hexdec($b['4'].$b['5']);
// main top
$imgname = '../images/kits/test/'. $uTime .'.png';
$im = imagecreatetruecolor(100, 100);
$red = imagecolorallocate($im, $aR, $aG, $aB);
imagefill($im, 0, 0, $red);
$mask = imagecreatefrompng('../images/kits/test/6-space.png');
imagecopyresampled($im, $mask, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($mask), imagesy($mask));
imagedestroy($mask);
$mask = imagecreatefrompng('../images/kits/test/4-shadows.png');
imagecopyresampled($im, $mask, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($mask), imagesy($mask));
imagedestroy($mask);
$mask = imagecreatefrompng('../images/kits/test/1-tag.png');
imagecopyresampled($im, $mask, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($mask), imagesy($mask));
imagedestroy($mask);
// design
$im2 = imagecreatetruecolor(100, 100);
$red = imagecolorallocate($im2, $bR, $bG, $bB);
imagefill($im2, 0, 0, $red);
$mask = imagecreatefrompng('../images/kits/test/5-logo.png');
imagecopyresampled($im2, $mask, 0, 0, 0, 0, imagesx($im2), imagesy($im2), imagesx($mask), imagesy($mask));
imagedestroy($mask);
imagecolortransparent($im2, imagecolorallocatealpha($im2, 0, 0, 0, 127));
imagealphablending($im2, false);
imagesavealpha($im2, true);
$white = imagecolorallocate($im2,255,255,255);
imagecolortransparent($im2, $white);
// merge and result
imagecopyresampled($im, $im2, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($im2), imagesy($im2));
imagepng($im, $imgname);
imagedestroy($im2);
imagedestroy($im);
echo '<img src="', $imgname ,'">';
?>
作为一个方面说明的%时,我输出的图像,它显示白色255,255,255和254,254,254。此外,如果我使用imagecolorset,它似乎没有做任何事情:/ – DugoutSoccer 2012-04-27 22:12:54
出于兴趣,你为什么用Imagemagick标记它时,它正在使用GD? – Bonzo 2012-04-28 14:29:20
在Imagemagick中有一些可以完成的功能...我对操纵图像很新颖,所以建议的任何内容都可能有所帮助......似乎没有人知道答案,那么也许太困难了? :P – DugoutSoccer 2012-04-28 18:14:09