change transparent image color dynamically
-
06-02-2021 - |
Question
i have to change image color dynamically using php i used the following code
$imgname = "source.png";
$im = imagecreatefrompng ($imgname);
if($im && imagefilter($im, IMG_FILTER_COLORIZE, 27, 133, 85))
{
echo 'Image successfully shaded as per color.';
imagepng($im, 'Result.png');
imagedestroy($im);
}
else
{
echo 'Image create succesfully.';
}
but when i used it with transparent image it show me large thing border
can we resolve using the GD Lib or image stick any function ???
Solution
if you are talking about quality issue or shadow issue then I can be resolve by using imagesavealpha
function before applying filter.
code should be
<?php
$imgname = "source.png";
$im = imagecreatefrompng ($imgname);
imagesavealpha($im, true);
if($im && imagefilter($im, IMG_FILTER_COLORIZE, 27, 133, 85))
{
echo 'Image successfully shaded as per color.';
imagepng($im, 'Result.png');
imagedestroy($im);
}
else
{
echo 'Image create succesfully.';
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow