PHP - Detect if a PNG is fully transparent


I am looking for a fast an reliable way of knowing if a PNG file hosted on an HTTP server is fully transparent (not even one pixel has color).

The PHP script doing that would have to process tens of thousands of images so it must be as fast as possible. I cannot afford a manual PHP for loop on all the pixels.

The images will be roughly 300x300px. They will be in PNG-8 format, so transparency is present but without alpha channel. I can use GD of course.

(If there is absolutely no way with PHP i can still switch to Node.js)

Fully Transparent image file example Transparent image

Not fully transparent image file example Not fully transparent image


Answers:


Usefull library : http://github.com/thephpleague/color-extractor

Basic usage :

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();