Possible Duplicate:
Translate Ruby into PHP code with the following code
I found a very useful Ruby code on to remove image white background color.
Please see reference code below: Remove white background from an image and make it transparent
I tried to translate the code into php. However I am getting an unwanted result. This is my first time post question here, can someone please give me some guideline and forgive my poor English.
function setTransparency($new_image,$image_source)
{
$transparencyIndex = imagecolortransparent($image_source);
$transparencyColor = array('red' => 255, 'green' => 255, 'blue' => 255);
if ($transparencyIndex >= 0) {
$transparencyColor = imagecolorsforindex($image_source, $transparencyIndex);
}
$transparencyIndex = imagecolorallocate($new_image, $transparencyColor['red'], $transparencyColor['green'], $transparencyColor['blue']);
imagefill($new_image, 0, 0, $transparencyIndex);
imagecolortransparent($new_image, $transparencyIndex);
}
//create image from the source link
$image = imagecreatefrompng('https://i.stack.imgur.com/k7E1F.png');
//create image mask layer
$new_image = ImageCreateTruecolor(imagesx($image), imagesy($image));
//remove white background
setTransparency($new_image,$image);
//merge mask with original image source
ImageCopyMerge($new_image, $image, 0, 0, 0, 0, imagesx($image), imagesy($image), 100);
imagejpeg($new_image, null, 95);