Php/docs/function.imagepalettetotruecolor

提供:Dev Guides
< Php
移動先:案内検索

imagepalettetotruecolor

(PHP 5 >= 5.5.0, PHP 7)

imagepalettetotruecolorパレット形式の画像を true color に変換する


説明

imagepalettetotruecolor ( resource $src ) : bool

imagecreate() のような関数で作ったパレット形式の画像を、 imagecreatetruecolor() で作るような true color 形式に変換します。


パラメータ

image
imagecreatetruecolor() のような画像作成関数が返す画像リソース。


返り値

変換に成功した場合や、元画像が既に 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

参考