我有一個具有圖像正常工作不透明度:imagecopymerge不與部分透明的圖像
當我嘗試加載它:
$img = imagecreatefrompng('cheek-01.png');
header('Content-Type: image/png');
imagepng($img);
就會變成:
我w螞蟻添加(合併)此圖像與另一個圖像(我知道如何可以合併兩個PNG圖像)。 問題是怎麼回事,如何在不丟失透明度的情況下使用GD
庫加載它?
更新
我的目標是合併一些圖片,其中有的已經阿爾法(不透明度不同,像上面的圖片),但是當我把它們合併阿爾法信息丟失。
<?php
$background = imagecreatetruecolor(3508, 2480);
// set background to white
$white = imagecolorallocate($background, 255, 255, 255);
imagefill($background, 0, 0, $white);
$dest = $background;
$items = array(
'cloth-1763-1249' => 'cloth-01.png',
'skin-167-59' => "skin-01.png",
'cheek-2247-1193' => 'cheek-09.png',
'hair-167-59' => 'hair-07.png'
);
foreach ($items as $i => $item) {
$src = imagecreatefrompng($item);
imagealphablending($src, true);
imagesavealpha($src, true);
imagecolortransparent($src, 2130706432);
$src_x = imagesx($src);
$src_y = imagesy($src);
$list = explode('-', $i);
//var_dump($list);
imagecopymerge($dest, $src, intval($list[1]), intval($list[2]), 0, 0, $src_x, $src_y, 100);
imagealphablending($dest, true);
imagesavealpha($dest, true);
}
header('Content-Type: image/png');
imagepng($dest);
tnx爲您的答案,它只是工作,但我有問題,但我更新了問題。 – zhilevan 2014-12-08 06:04:04
你知道爲什麼嗎? – zhilevan 2014-12-15 14:28:42
編輯我的代碼的功能,可能會幫助 – jabbink 2014-12-15 23:01:37