問題描述
我真的找不到成功的方法.我在谷歌上搜索過這個,它要么在圖像周圍有黑色陰影,要么所有圖像都不重疊.你能幫忙嗎?
I really cannot find a way to successfully do it.. I've searched google for this and it either has black shades around the images or all the images don't overlap. Could you please help?
我擅長 PHP;我會給自己 2/5.. 如果有人愿意幫助我,我真的很感激.
I am alright at PHP; I'd give myself a 2/5.. I would really appreciate if someone would be willing to help me out.
我正在尋找一個簡單的 api,類似于:
I'm looking for a simple api that goes something like:
$color=$_GET['color'];
$face=$_GET['face'];
$hat=$_GET['hat'];
echo '<img src="avatar.php?color=$color&face=$face&hat=$hat">';
提前感謝您的任何幫助.我也可以通過我對其他語言的了解來理解 php,所以不要害怕和我談論技術;但不要太技術化.
Thanks for any help in advance. I can understand php from my knowledge of other languages, too, so don't be afraid to talk technical with me; but not too technical.
推薦答案
關于這個答案的評論太多了,所以我把它作為答案發布.
there are so many comments on this answer so I'm posting this as an answer.
讓它在我的電腦上工作.
Got it working on my pc.
使用斯文代碼:
$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);
?>
我像這樣重命名了你的圖片,這樣更容易:
I renamed your images like this so its easier :
微笑:a.png
耳機:b.png
藍色:c.png
smile : a.png
headset : b.png
blue : c.png
原來問題在于它的分層.把一個放在另一個后面
重命名圖像后,使用此 url -- 它將起作用(在我的 PC 上起作用).
after you rename the images, use this url -- it will work(works on my pc).
YOUR_FILE.php?hat=b.png&color=c.png&face=a.png
YOUR_FILE.php?hat=b.png&color=c.png&face=a.png
這仍然會給你一個黑色的背景.我不確定您在服務器上的文件中是否具有與上述完全相同的代碼 - 因為我在您的鏈接上使用了圖像順序,但它沒有幫助.嘗試將此完全相同的代碼復制粘貼到不同的文件上,然后嘗試.處理訂單并檢查結果.
This will still give you a black background. I am not sure if you have the exact same code as above in your file on the server - because I played around with the image order on your link and it does not help. Try copy-pasting this exact same code on a different file and then trying. Play around with the order and check the results.
這篇關于如何通過 PHP 將 3 個圖像合并為 1 個圖像?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!