M
M
Mikhail2016-04-27 15:02:03
PHP
Mikhail, 2016-04-27 15:02:03

How to make transparency for webp in php?

Good day, I am converting from the format of incoming images to webp, but unfortunately, for some reason, transparency is not saved in webp, although it supports it.
Tell me how to fix the situation?

function createWebpImage2($link,$name){
    if(file_exists($link)){
        $a = exif_imagetype($link);
        switch($a){
            case 1:
                $source =  imagecreatefromgif($link);
                break;
            case 2:
                $source = imagecreatefromjpeg($link);
                break;
            case 3:
                $source =  imagecreatefrompng($link);
                break;
            default: $source=false;
        }
    }

    else{
        return false;

    }
        imagealphablending($source, false);
        imagesavealpha($source, true);
        imagewebp($source,$name.'.webp');
        imagedestroy($source);
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question