imagepalettetotruecolor
(PHP 5 >= 5.5.0, PHP 7)
imagepalettetotruecolor — パレット形式の画像を true color に変換する
説明
imagepalettetotruecolor
( resource $src
) : bool
imagecreate() のような関数で作ったパレット形式の画像を、 imagecreatetruecolor() で作るような true color 形式に変換します。
返り値
変換に成功した場合や、元画像が既に true color だった場合に true
を返します。
それ以外の場合に false
を返します。
例
例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