Klajdi Dosti Klajdi Dosti - 2 years ago 117
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

Answer Source
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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download