array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.imagepalettetotruecolor.php', 1 => 'imagepalettetotruecolor', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD および Image 関数', ), 'prev' => array ( 0 => 'function.imagepalettecopy.php', 1 => 'imagepalettecopy', ), 'next' => array ( 0 => 'function.imagepng.php', 1 => 'imagepng', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/image/functions/imagepalettetotruecolor.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.5.0, PHP 7, PHP 8)
imagepalettetotruecolor — パレット形式の画像を true color に変換する
imagecreate() のような関数で作ったパレット形式の画像を、 imagecreatetruecolor() で作るような true color 形式に変換します。
バージョン | 説明 |
---|---|
8.0.0 |
image は、
GdImage
クラスのインスタンスを期待するようになりました。
これより前のバージョンでは、有効な gd resource が期待されていました。
|
例1 画像オブジェクトの true color への変換
<?php
// 過去との互換性のための処理
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);
}
}
// ヘルパークロージャ
$typeof = function() use($im)
{
echo 'typeof($im) = ' . (imageistruecolor($im) ? 'true color' : 'palette'), PHP_EOL;
};
// パレット形式の画像を作ります
$im = imagecreate(100, 100);
$typeof();
// true color に変換します
imagepalettetotruecolor($im);
$typeof();
// メモリを解放します
imagedestroy($im);
?>
上の例の出力は以下となります。
typeof($im) = palette typeof($im) = true color