Advertisement
Guest User

Untitled

a guest
Jun 30th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. $pngimg = imagecreatefrompng($file);
  2.  
  3. $w = imagesx($pngimg);
  4. $h = imagesy($pngimg);;
  5.  
  6. $im = imagecreatetruecolor ($w, $h);
  7. imageAlphaBlending($im, false);
  8. imageSaveAlpha($im, true);
  9.  
  10. $trans = imagecolorallocatealpha($im, 0, 0, 0, 127);
  11. imagefilledrectangle($im, 0, 0, $w - 1, $h - 1, $trans);
  12.  
  13. imagecopy($im, $pngimg, 0, 0, 0, 0, $w, $h);
  14.  
  15. imagewebp($im, str_replace('png', 'webp', $file), 100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement