Klajdi Dosti Klajdi Dosti - 1 month ago 6x
CSS Question

how to make a image background transparent with php

I want to make background of my image transparent(mean to take my webpage background color).Have any php function to make that?
For example the white color of this image to change to my background color.

enter image description here

function transparent_background($filename, $color) 
    $info = getimagesize($filename);
    if ($info['mime'] == 'image/jpeg') 
        $img = imagecreatefromjpeg($filename);

    elseif ($info['mime'] == 'image/gif') 
        $img = imagecreatefromgif($filename);

    elseif ($info['mime'] == 'image/png') 
        $img= imagecreatefrompng($filename);
    //$img = imagecreatefromjpeg($filename);
    $colors = explode(',', $color);
    $remove = imagecolorallocate($img, $colors[0], $colors[1], $colors[2]);
    imagecolortransparent($img, $remove);

this is the solution