如何使用 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