Ich versuche, ein transparentes PNG-Bild und verschiedene andere PNGs und JPGs zu erstellen, um ein endgültiges PNG mit Transparenz zu erstellen. Ich habe Probleme beim Erstellen meines ersten leeren transparenten PNG. Es hat derzeit einen weißen Hintergrund.
Kann mir jemand die richtige Richtung zeigen. Dies ist mein Code bisher ...
$image = imagecreatetruecolor(485, 500);
imagealphablending($image, false);
imagesavealpha($image, true);
$col=imagecolorallocatealpha($image,255,255,255,127);
imagefill($image, 0, 0, $col);
//imagefilledrectangle($image,0,0,485, 500,$col);
/* add door glass */
$img_doorGlass = imagecreatefrompng("glass/$doorStyle/$doorGlass.png");
imagecopyresampled($image, $img_doorGlass, 106, 15, 0, 0, 185, 450, 185, 450);
/* add door */
$img_doorStyle = imagecreatefrompng("door/$doorStyle/$doorStyle"."_"."$doorColor.png");
imagecopyresampled($image, $img_doorStyle, 106, 15, 0, 0, 185, 450, 185, 450);
$fn = md5(microtime()."door_builder").".png";
if(imagepng($image, "user_doors/$fn", 1)){
echo "user_doors/$fn";
}
imagedestroy($image);
Setze imagealphablending($image,true);
auf jeder neuen Ebene.
Versuche dies:
<?php
$image = imagecreatetruecolor(485, 500);
imagealphablending($image, false);
$col=imagecolorallocatealpha($image,255,255,255,127);
imagefilledrectangle($image,0,0,485, 500,$col);
imagealphablending($image,true);
/* add door glass */
$img_doorGlass = imagecreatefrompng("glass/$doorStyle/$doorGlass.png");
imagecopyresampled($image, $img_doorGlass, 106, 15, 0, 0, 185, 450, 185, 450);
imagealphablending($image,true);
/* add door */
$img_doorStyle = imagecreatefrompng("door/$doorStyle/$doorStyle"."_"."$doorColor.png");
imagecopyresampled($image, $img_doorStyle, 106, 15, 0, 0, 185, 450, 185, 450);
imagealphablending($image,true);
$fn = md5(microtime()."door_builder").".png";
imagealphablending($image,false);
imagesavealpha($image,true);
if(imagepng($image, "user_doors/$fn", 1)){
echo "user_doors/$fn";
}
imagedestroy($image);
?>
Dieser Code hat für mich funktioniert:
$img=imagecreatetruecolor(180,20);
imagealphablending($img,false);
$col=imagecolorallocatealpha($img,255,255,255,127);
imagefilledrectangle($img,0,0,180,20,$col);
imagealphablending($img,true);
$font=$_SERVER["DOCUMENT_ROOT"].'/fonts/Arial.ttf';
$color = imagecolorallocate($img, 140, 173, 209);
imagettftext($img,11,0,5,14,$color,$font,'Text goes here');
header('Content-Type: image/png');
imagealphablending($img,false);
imagesavealpha($img,true);
imagepng($img);
Versuchen Sie zu ersetzen$col=imagecolorallocatealpha($image,255,255,255,127);
mit$col=imagecolorallocate($image,255,255,255);
und versuchen Sie, die Zeile imagefilledrectangle
zu dekommentieren.
Ich kann diesen Code testen - gib mir die Bilder :)