PHP 8.3.4 Released!

imageistruecolor

(PHP 4 >= 4.3.2, PHP 5, PHP 7, PHP 8)

imageistruecolor画像が truecolor かどうか調べる

説明

imageistruecolor(GdImage $image): bool

imageistruecolor() は、 image が truecolor 画像かどうか調べます。

パラメータ

image

imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。

戻り値

image が truecolor の場合に true、 それ以外の場合に false を返します。

変更履歴

バージョン 説明
8.0.0 image は、 GdImage クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な gd resource が期待されていました。

例1 imageistruecolor() による、シンプルな true color 画像の検出

<?php
// $im は画像のインスタンスです

// それが true color 画像か否かを調べます
if(!imageistruecolor($im))
{
// 新しい true color 画像のインスタンスを作成します
$tc = imagecreatetruecolor(imagesx($im), imagesy($im));

// ピクセルをコピーします
imagecopy($tc, $im, 0, 0, 0, 0, imagesx($im), imagesy($im));
imagedestroy($im);

$im = $tc;
$tc = NULL;

// あるいは imagepalettetotruecolor() を使います
}

// 画像のインスタンスに対する操作を続けます
?>

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top