如何使用 PHP 中的 imageistruecolor() 函式確保影像為真彩色影像?


imageistruecolor() 是 PHP 中一個內建函式,用於檢查給定的影像是否為真彩色影像。在真彩色影像中,每個畫素都由 RGB(紅、綠、藍)顏色值指定。

語法

bool imageistruecolor(resource $image)

引數

imageistruecolor() 接受一個引數,$image。它儲存影像。

返回值

如果給定影像為真彩色,則 imageistruecolor() 返回 True;否則,如果影像不是真彩色影像,則返回 False。

示例 1

<?php
   // Create an image instance with a true-color image using
   //imagecreatefrompng() function.
   $img = imagecreatefrompng('C:\xampp\htdocs\Images\img44.png');

   // Checked if the image is true-color
   $istruecolor = imageistruecolor($img);

   // Show the output image to the browser
   if($istruecolor) {
      echo "The given input image is true-color";
   }
?>

輸出

// 輸入 RGB 影像

// 結果輸出

The given input image is true-color.

示例 2

<?php
   // Create an image instance with a true-color image using
   //imagecreatefrompng() function.
   $img = imagecreatefrompng('C:\xampp\htdocs\Gray.png');
   
   // Checked if the image is true-color
   $istruecolor = imageistruecolor($img);
 
    // Show the output image to the browser
   if($istruecolor) {
      echo "The given input image is not a true-color";
   }
?>

輸出

// 輸入灰度影像。

// 輸出

The given input image is not a true-color image.

更新於: 2021年8月9日

169 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.