Função para remover fundo de imagem


SUBMITTED BY: Guest

DATE: Oct. 20, 2020, 1:52 p.m.

FORMAT: Text only

SIZE: 681 Bytes

HITS: 437

  1. <?php
  2. $fileName = ('https://alunos.b7web.com.br/media/courses/php.jpg');
  3. list($width, $height) = getimagesize($fileName);
  4. $newwidth = 400;
  5. $newheight = 283;
  6. $thumb = imagecreatetruecolor($newwidth, $newheight);
  7. imagealphablending($thumb, false);
  8. imagesavealpha($thumb, true);
  9. $trans = imagecolorallocatealpha($thumb, 220, 220, 220, 127);
  10. imagefill($thumb, 0, 0, $trans);
  11. $source = imagecreatefrompng($fileName);
  12. imagealphablending($source, true);
  13. imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  14. header('Content-Type: image/png');
  15. imagepng($thumb, 'test.png');
  16. imagedestroy($thumb);
  17. imagedestroy($source);

comments powered by Disqus