Color percentage with php

Asked

Viewed 49 times

0

I set up a real estate website, and I’m trying to make it as automated as possible to upload images of real estate centered on one-size images with a white background up to ai blz, but I got to the part of the banners that is made automatic as the real estate giveaway has lots of pictures with the white sides.

My idea was select images that don’t have that white background where the percentage of white is the lowest possible, run a php would put this percentage in the photo table and make a where in that field.

It would have something in php that can read an image and determine which color appears the most or how much of a "white" color appears in this image?

1 answer

1


You can use the library Colorextractor:

This class can be used to extract the most common colors used in images.

You can open an image file in GIF, JPEG or PNG format. It then traverses the image and returns a matrix with the percentage of the most commonly used color tones.

<?php

require_once 'colors.inc.php';
$ex=new GetMostCommonColors();
$num_results=20;
$reduce_brightness=1;
$reduce_gradients=1;
$delta=24;


$colors=$ex->Get_Color( 'image.png', $num_results, $reduce_brightness, $reduce_gradients, $delta);


echo json_encode($colors, JSON_PRETTY_PRINT);

Results converted to JSON:

{
"300090": 0.0034146341463415,
"ffffff": 0.53479674796748,
"6000f0": 0.16308943089431,
"f0f0f0": 0.052682926829268,
"a878f0": 0.032520325203252,
"d8d8f0": 0.029756097560976,
"4890f0": 0.02260162601626,
"f0fff0": 0.021463414634146,
"7848f0": 0.01869918699187,
"c0a8f0": 0.018211382113821,
"6018f0": 0.018048780487805,
"48c0f0": 0.01609756097561,
"9060f0": 0.013983739837398,
"fffff0": 0.013658536585366,
"a8f0f0": 0.008130081300813,
"f0f0ff": 0.0079674796747967,
"f0ffff": 0.0066666666666667,
"48ffd8": 0.0063414634146341,
"78ffd8": 0.0027642276422764,
"a878ff": 0.0022764227642276
}

Requirements:

PHP 4.0.2 ou maior  
GD2 image library  

Browser other questions tagged

You are not signed in. Login or sign up in order to post.