简体   繁体   English

php如何为php图像添加透明背景颜色?

[英]php how add transparent background color for php image?

background is comming in white i want to remove white and put transparent.please help 背景是白色的我想要删除白色和放透明。请帮助

this is an image: http://funbusy.com/fbtest/user_image.php 这是一张图片: http//funbusy.com/fbtest/user_image.php

?php

// Create the image
$im = imagecreatetruecolor(400, 25);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 22, 125, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = ucwords('tanuja sree');
// Replace path by your own font path
$font = 'OpenSans-Italic.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
ob_start();
imagepng($im);
$image_data = ob_get_clean();
$image_code = '<img id="image_code" src="data:image/png;base64,'.        base64_encode($image_data) . '">';
imagedestroy($im);

?>

Try adding this piece of code after imagettftext($im, 20, 0, 10, 20, $black, $font, $text); 尝试在imagettftext($im, 20, 0, 10, 20, $black, $font, $text);之后添加这段代码imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

imagecolortransparent($im, $white);
imagesavealpha($im,true);
imagealphablending($im, true); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM