我正在寻找一种快速可靠的方法来了解HTTP服务器上托管的PNG文件是否完全透明(甚至一个像素都没有颜色)。
执行此操作的PHP脚本必须处理成千上万的图像,因此必须尽可能快。我买不起所有像素上的手动PHP for循环。
图像大约为300x300px。它们将采用PNG-8格式,因此存在透明度,但没有alpha通道。 我当然可以使用GD。
(如果PHP完全没办法,我仍然可以切换到Node.js)
答案 0 :(得分:1)
有用的库:http://github.com/thephpleague/color-extractor
基本用法:
require 'vendor/autoload.php';
use League\ColorExtractor\Client as ColorExtractor;
$client = new ColorExtractor;
$image = $client->loadPng('./some/image.png');
// Get the most used color hexadecimal codes from image.png
$palette = $image->extract();