I\'m new here on Stackoverflow.
I would very much like figure out if it\'s possible to make a specific color of an image transparent using a PHP script. And if it is, ho
imagecolortransparent() will help you:
...
$yourColor = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, $yourColor);
...
- demo : http://so.devilmaycode.it/php-how-to-make-a-green-area-background-in-an-image-transparent
first of all the image should be png cause jpeg don't support transparency then the code is like this:
<?php
$image = 'test.png';
$im = imagecreatefrompng($image);
//if you exactly know the RGB color indexes
//$rgb = imagecolorexact($im, 0, 0, 0);
//or keep the rgb color by position so at top 0 left 0
$rgb = imagecolorat($im, 0, 0);
imagecolortransparent($im, $rgb);
header("Content-type: image/png");
//display the image directly
imagepng($im);
// or save it
// imagepng($im, 'test-to-transparent.png');
imagedestroy($im);
?>