Guest User

Untitled

a guest
Aug 10th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. How to create an image with transparent background
  2. header('content-type: image/png');
  3.  
  4. $image = imagecreatetruecolor(900, 350);
  5.  
  6. imagealphablending($image, true);
  7. imagesavealpha($image, true);
  8.  
  9. $text_color = imagecolorallocate($image, 0, 51, 102);
  10. imagestring($image,2,4,4,'Test',$text_color);
  11.  
  12. imagepng($image);
  13. imagedestroy($image);
  14.  
  15. imagefill($image,0,0,0x7fff0000);
  16.  
  17. alpha = 0x7f
  18. red = 0xff
  19. green = 0x00
  20. blue = 0x00
  21.  
  22. $im = @imagecreatetruecolor(100, 25);
  23. # important part one
  24. imagesavealpha($im, true);
  25. imagealphablending($im, false);
  26. # important part two
  27. $white = imagecolorallocatealpha($im, 255, 255, 255, 127);
  28. imagefill($im, 0, 0, $white);
  29. # do whatever you want with transparent image
  30. $lime = imagecolorallocate($im, 204, 255, 51);
  31. imagettftext($im, $font, 0, 0, $font - 3, $lime, "captcha.ttf", $string);
  32. header("Content-type: image/png");
  33. imagepng($im);
  34. imagedestroy($im);
Add Comment
Please, Sign In to add comment