이미지 처리 및 GD imagecolortransparent

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecolortransparent — 색상을 투명으로 정의


설명

imagecolortransparent(GdImage $image, ?int $color = null): int

지정된 image의 투명 색상을 가져오거나 설정합니다.


매개변수

image
imagecreatetruecolor()와 같은 이미지 생성 함수 중 하나에서 반환되는 GdImage 객체.
color
imagecolorallocate()로 생성된 색상 식별자입니다.

반환 값

새(또는 지정되지 않은 경우 현재) 투명 색상의 식별자가 반환됩니다. colornull이고 이미지에 투명 색상이 없으면 반환된 식별자는 -1이 됩니다.


변경 로그

버전 설명
8.0.0 image는 이제 GdImage 인스턴스를 예상합니다. 이전에는 리소스가 필요했습니다.
8.0.0 color은 이제 nullable입니다.

Examples

예제 #1 imagecolortransparent() 예제

                  
<?php
// Create a 55x30 image
$im = imagecreatetruecolor(55, 30);
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);

// Make the background transparent
imagecolortransparent($im, $black);

// Draw a red rectangle
imagefilledrectangle($im, 4, 4, 50, 25, $red);

// Save the image
imagepng($im, './imagecolortransparent.png');
imagedestroy($im);
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

function imagecolortransparent


메모

메모: 투명도는 imagecopy() 또는 팔레트 이미지가 아닌 imagecopymerge() 및 트루 컬러 이미지로만 복사됩니다.

메모: 투명한 색상은 이미지의 속성이고 투명도는 색상의 속성이 아닙니다. 색상을 투명 색상으로 설정하면 이전에 그린 해당 색상의 이미지 영역이 모두 투명해집니다.