php - Color overlay on white PNG image with transparency -
i have following image: http://i.stack.imgur.com/mm8cy.png
what create "color overlay" effect in photoshop. need sort of code allow me change each white pixels values specified in rgb numbers ranging 0-255. have heard imagemagick class, not find anywhere, , have no idea how class. i'm trying imagefilter
, doesn't work white images. here current code:
<?php $match = array(); if (isset($_get['c']) && preg_match('/^#?(?:[a-fa-f0-9]{2}){3}$/',$_get['c'],$match)){ $match = str_split($match[0],2); foreach ($match $k=>$m){ $match[$k] = intval($match[$k],16); } $img = imagecreatefrompng('splat.png'); $background = imagecolorallocate($img, 0, 0, 0); imagecolortransparent($img, $background); imagealphablending($img, false); imagesavealpha($img, true); //transformation code imagefilter($img, img_filter_colorize, $match[0], $match[1], $match[2]); header('content-type: image/png'); imagepng($img); exit; } ?>
i found solution. did - using photoshop - added red color overlay on image, looks this: http://i.stack.imgur.com/mvarn.png
and used following php code:
<?php $match = array(); $color = isset($_get['c']) ? $_get['c'] : false; if ($color === false) isset($_get['color']) ? $_get['color'] : false; $color = preg_replace('/^#/','',$color); if (strlen($color) == 3) $color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2]; if (preg_match('/^(?:[a-fa-f0-9]{2}){3}$/',$color,$match)){ $match = str_split($match[0],2); foreach ($match $k=>$m){ $match[$k] = intval($match[$k],16); } // load image $img = imagecreatefrompng('splat.png'); $background = imagecolorallocate($img, 0, 0, 0); imagecolortransparent($img, $background); imagealphablending($img, false); imagesavealpha($img, true); imagefilter($img, img_filter_colorize, intval( intval($match[0],16) - 255 ,16), $match[1], $match[2]); header('content-type: image/png'); imagepng($img); exit; } ?>
the key here substracted 255 red color value input this:
intval( intval($match[0],16) - 255 ,16)
and changed color properly.
Comments
Post a Comment