• Resolved kolshix

    (@kolshix)


    how to keep transparency from PNG to WEBP ?
    I use code for thumbnail

    
    add_filter('wp_generate_attachment_metadata', 'custom_webp_thumb');
    
    function custom_webp_thumb($metadata) {
    	// URL
    	$uploads = wp_upload_dir();	 // 
    	$path_parts  = pathinfo($metadata['file']);  // for 2018/10
    	
    	$file = path_join( $uploads['basedir'], $path_parts['dirname'].'/'. $metadata["sizes"]["medium"]["file"] ); // original image file
    	$image = imagecreatefrompng($file); // or imagecreatefromjpeg
    	
    //	imagepalettetotruecolor($image); - not help 
    //	imagealphablending($image, false); - not help 
    //	imagesavealpha($image, true); - not help 
    		
    	// Save the image
    	imagewebp($image, '/home/****/2018/10/'.$metadata["sizes"]["medium"]["file"].'.webp');
    	// unlink($file);
    	
    	return $metadata;
    }
    

    pictures are obtained with a black and not transparent background

    ——— PNG with transparency ————- WEBP with Black background —–
    3a1S.png

    • This topic was modified 7 years, 7 months ago by kolshix.
    • This topic was modified 7 years, 7 months ago by kolshix.
    • This topic was modified 7 years, 7 months ago by kolshix.
Viewing 2 replies - 1 through 2 (of 2 total)
  • This is not a WordPress question. You might try the PHP docs or StackOverflow or some other developer site.

    Thread Starter kolshix

    (@kolshix)

    tried on another hosting, everything works well,
    problem in the settings of the hosting or PHP
    (I did not find the solution)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘webp with transparency’ is closed to new replies.