【发布时间】:2017-11-17 06:12:46
【问题描述】:
我想在 PHP 中获得给定图像的确切“灰度”。我不明白为什么我总是使用imagecolorsforindex 将[0, 0, 0] 作为RGB 数组。这是我的代码:
// load
$img = imagecreatefromjpeg("images/white.jpeg");
// to grayscale
imagefilter($img, IMG_FILTER_GRAYSCALE);
// just 1 pixel that describe the whole image
$grayLevel = resize_image($img, 1, 1);
$gray = imagecolorat($grayLevel, 1, 1);
$readble = imagecolorsforindex($grayLevel, $gray);
print_r($readble);
我首先加载我的图像(这是一张全白图像,因此根据this,每个像素都应该是 [255, 255, 255]),然后将其转换为灰度。我将图像大小调整为仅描述整个图像的一个像素,然后得到 RGB 数组。数组是[0, 0, 0]。
我不明白为什么我总是收到带有灰度和彩色图像的[0, 0, 0]。 1 像素技术错了吗?
非常感谢
PS:resize_image 有效,我已经测试过了,无论如何这是代码:https://pastebin.com/HNDzKq5E
【问题讨论】: