2011-07-24 6 views
0

Je veux faire une image png transparente, et imprimer une chaîne par imagefttext (par couleur noire). J'ai lu quelques exemples, je pense que je devrais utiliser la fonction imagecolortransparent, mais cela fait de l'image sur fond noir. comment dois-je faire?faire une image png transparente par gd

Répondre

6

Essayez cette

<?php 
//Canvas size 100x50 
$image = imagecreatetruecolor(100, 50); 
imagealphablending($image, false); 
//Create alpha channel for transparent layer 
$col=imagecolorallocatealpha($image,255,255,255,127); 
//Create overlapping 100x50 transparent layer 
imagefilledrectangle($image,0,0,100, 50,$col); 
//Continue to keep layers transparent 
imagealphablending($image,true); 
//Insert the text 
imagefttext($image,10,0,10,20,0,'octin.ttf','test sting'); 
//Keep trnsparent when saving 
imagesavealpha($image,true); 

//Save & output 
if(imagepng($image, "test.png", 1)){ 
    header("Content-Type: image/png"); 
    readfile('test.png'); 
} 
imagedestroy($image); 
?> 

sortie 100x50px [test.png]

Output

oups j'ai oublié le r ... mon mauvais

+0

belle, ce qui est excellent. J'ai travaillé, mais j'ai dû ajouter la directive realpath de police comme ceci: $ fontpath = realpath ('.'); Putenv ('GDFONTPATH ​​='. $ Fontpath) ; – rncrtr

Questions connexes