imagepalettetotruecolor()函數是PHP中的內置函數,用於將基於調色板的圖像轉換為真彩色。
用法:
bool imagepalettetotruecolor( resource $src )
參數:該函數接受單個參數$src,該參數保存要處理的圖像。
返回值:如果轉換完成,或者源圖像已經是真彩色圖像,則此函數返回TRUE,否則返回FALSE。
下麵給出的程序說明了PHP中的imagepalettetotruecolor()函數:
程序1:
<?php 
  
// Create an image 
$image = imagecreate(700, 200); 
  
echo '<b>Before conversion:</b> <br>'; 
  
// Check the image type 
check($image); 
  
echo '<b><br>After conversion:</b> <br>'; 
  
// Convert image to true color 
imagepalettetotruecolor($image); 
  
// Check the image type 
check($image); 
  
// Function for cheching the image type 
function check($image) { 
    echo 'Type of image is ' . (imageistruecolor($image) 
             ? 'true color' :'palette'); 
} 
?>輸出:
Before conversion: Type of image is palette After conversion: Type of image is true color
程序2:
<?php 
  
// Create an image of pallete type 
$image = imagecreate(700, 200); 
  
// Convert image to true color 
imagepalettetotruecolor($image); 
  
// Prepare red color 
$red = imagecolorallocate($image, 0xFF, 0x00, 0x00); 
  
// Add text to the image using a local font file 
imagefttext($image, 100, 0, 0, 130, $red,  
       './RugeBoogie-Regular.ttf', 'GeeksforGeeks'); 
  
// Output to browser 
header('Content-type:image/png'); 
imagepng($image); 
imagedestroy($image); 
?>輸出:

參考: https://www.php.net/manual/en/function.imagepalettetotruecolor.php
相關用法
- p5.js pow()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js second()用法及代碼示例
- PHP next()用法及代碼示例
- CSS url()用法及代碼示例
- PHP pow( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- CSS var()用法及代碼示例
- p5.js day()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- p5.js hue()用法及代碼示例
- p5.js value()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagepalettetotruecolor() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
