2017-12-30 34 views
0

gd를 사용하여 이미지에 색상 레이어를 추가하고 싶습니다. ImagePHP GD - 이미지 위에 색상 레이어 추가

나는이 색이 오버레이 할 :

은 이미지 #의 ABD0D2

내가이 말을보고하는 방법을 빠른 이미지를했다.

$img = imagecreatefrompng('image.png'); 

imagesavealpha($img, true); 
imagefill($img, 0, 0, imagecolorallocatealpha($img, 0, 0, 0, 127)); 

// make overlay with new color??? 

imagepng($img, 'new.png'); 
imagedestroy($img); 

답변

0

당신은 당신의 목표 색으로 채워진 새 이미지를 만든 다음 두 가지를 병합 할 수 있습니다 : 이미지가 여전히 투명 enter image description here

해야한다는 명심 지금까지 나는이 코드를 가지고 :

$img = imagecreatefrompng('image.png'); 
$w = imagesx($img); 
$h = imagesy($img); 
imagesavealpha($img, true); 

$img2 = imagecreatetruecolor($w, $h); 
imagefill($img2, 0, 0, imagecolorallocatealpha($img, 0xAB, 0xD0, 0xD2, 64)); 

imagecopy($img, $img2, 0, 0, 0, 0, $w, $h); 

imagepng($img, 'new.png'); 
imagedestroy($img); 
imagedestroy($img2); 

결과 :

enter image description here

투명도를 유지하는 방법 (예상 결과 이미지가 투명하지 않으므로)이 명확하지 않으므로 위 코드에서 50 % 불투명도로 '마스크'색을 설정했습니다.

+0

@Tafelglotzer이 답변을 원하십니까? – timclutton