PHP Determining Background Color of Image -


i've been looking @ customink's design lab , curious how decide color background color. example, if upload facebook logo, decide remove blue image.

enter image description here

but if upload picture of apple white background, remove white in similar fashion. (even though white background not dominant color)

using imagemagick in php, how achieve task?

i've found solution finding background color in image , removing php , imagick. i, instead of using edges, decided use corners figure out colors remove, seemed working of time. below results.

enter image description here

which able turn this

enter image description here

(the background image texture of white woven material found on google). seemed handle gradient backgrounds pretty decently well.

enter image description here

this picture of vette original first, changing corners' colors transparent, , final 1 using fill starting corners.

$image = new imagick('vette.jpg'); $backgroundcolors = array(     'topleft' => array(1, 1),     'topright' => array($image->getimagewidth(), 1),     'bottomleft' => array(1, $image->getimageheight()),     'bottomright' => array($image->getimagewidth(), $image->getimageheight()) );  foreach ($backgroundcolors $key => $bg) {     $pixel = $image->getimagepixelcolor($bg[0], $bg[1]);     $colors = $pixel->getcolor();     $excludedcolors[] = rgb2hex(array_values($colors));     $image->floodfillpaintimage('none', 9000, $pixel, $bg[0] - 1, $bg[1] - 1, false);     //comment line above , uncomment below line achieve effects of second vette     //$image->transparentpaintimage($pixel, 0, 9000, false); } $image->writeimage("vette-no_background.png"); 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -