我真的找不到一种成功的方法。我已经在谷歌上搜索过了,它要么是图像周围有黑色阴影,要么是所有的图像都不重叠。你能帮帮忙吗?
我在PHP上很好;我会给自己打2/5分。如果有人愿意帮助我,我将不胜感激。
我正在寻找一个简单的api,如下所示:
$color=$_GET['color'];
$face=$_GET['face'];
$hat=$_GET['hat'];
echo '<img src="avatar.php?color=$color&face=$face&hat=$hat">';提前感谢您的帮助。我也可以通过我对其他语言的了解来理解php,所以不要害怕和我谈技术上的,但不要太专业。
发布于 2010-12-12 07:20:24
这里有一些代码可以帮助您入门。但是,您应该注意到,使用gd和alpha通道进行图像处理是非常困难的。
<?php
$images = array( $_GET['color'], $_GET['face'], $_GET['hat'] );
// Allocate new image
$img = imagecreatetruecolor(58, 75);
// Make alpha channels work
imagealphablending($img, true);
imagesavealpha($img, true);
foreach($images as $fn) {
// Load image
$cur = imagecreatefrompng($fn);
imagealphablending($cur, true);
imagesavealpha($cur, true);
// Copy over image
imagecopy($img, $cur, 0, 0, 0, 0, 58, 75);
// Free memory
imagedestroy($cur);
}
header('Content-Type: image/png'); // Comment out this line to see PHP errors
imagepng($img);
?>现在您仍然需要检查返回值(查看手册中的image*函数),以确保它不会静默失败。
我真的不能保证它会和alpha通道一起工作。如果没有,您可能需要查看对php.net上的imagecopymerge()或imagecopy()的评论,看看我是否遗漏了什么。
https://stackoverflow.com/questions/4419383
复制相似问题