如何使用 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 影像
.jpg)
// 結果輸出
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"; } ?>
輸出
// 輸入灰度影像。
.jpg)
// 輸出
The given input image is not a true-color image.
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP