이미지 처리 및 GD imagepalettetotruecolor
(PHP 5 >= 5.5.0, PHP 7, PHP 8)
imagepalettetotruecolor — 팔레트 기반 이미지를 트루 컬러로 변환
설명
imagepalettetotruecolor(GdImage $image
): bool
imagecreate()와 같은 함수로 만든 팔레트 기반 이미지를 imagecreatetruecolor()와 같은 트루 컬러 이미지로 변환합니다.
매개변수
image
- imagecreatetruecolor()와 같은 이미지 생성 함수 중 하나에서 반환되는 GdImage 객체.
반환 값
변환이 완료되었거나 소스 이미지가 이미 트루 컬러 이미지인 경우 true
를 반환하고 그렇지 않으면 false
를 반환합니다.
변경 로그
버전 | 설명 |
---|---|
8.0.0 | image 는 이제 GdImage 인스턴스를 반환합니다. 이전에는 리소스가 필요했습니다. |
Examples
예제 #1 모든 이미지 개체를 트루 컬러로 변환
<?php
// Backwards compatiblity
if(!function_exists('imagepalettetotruecolor'))
{
function imagepalettetotruecolor(&$src)
{
if(imageistruecolor($src))
{
return(true);
}
$dst = imagecreatetruecolor(imagesx($src), imagesy($src));
imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src));
imagedestroy($src);
$src = $dst;
return(true);
}
}
// Helper closure
$typeof = function() use($im)
{
echo 'typeof($im) = ' . (imageistruecolor($im) ? 'true color' : 'palette'), PHP_EOL;
};
// Create a palette based image
$im = imagecreate(100, 100);
$typeof();
// Convert it to true color
imagepalettetotruecolor($im);
$typeof();
// Free the memory
imagedestroy($im);
?>
위의 예는 다음을 출력합니다.
typeof($im) = palette typeof($im) = true color
기타
- imagecreatetruecolor() - 새로운 트루 컬러 이미지 생성
- imageistruecolor() - 이미지가 트루컬러 이미지인지 여부를 찾습니다.