<?php
header ('Content-type: text/html');
$text_fname = "nove/text.png";
$mask_fname = "nove/mask.png";
// getimagesize vracia pole, preto ten list
list($text_width, $text_height) = getimagesize($text_fname);
list($mask_width, $mask_height) = getimagesize($mask_fname);
// natiahneme obrazok text a mask
$text = imagecreatefrompng($text_fname) or die ("chyba c.1");
$mask = imagecreatefrompng($mask_fname) or die ("chyba c.2");
// nastavime maske transparentnost na bielu farbu
$biela = imagecolorallocate ($mask, 255, 255, 255);
imagecolortransparent($mask,$biela);
// mozete si skontrolovat ze tam kde bola maska biela je teraz priehladna
imagepng($mask,"nove/1.png");
// vlozime masku do textu (tam kde je maska transparentna by malo byt vidiet text)
imagecopy($text,$mask,10,10,0,0,$mask_width,$mask_height);
// ulozime ako novy a zobrazime, problem je ten ze tam kde bola maska transparenta je biela!
imagepng($text,"nove/novy.png");
echo "<img src=\"nove/novy.png\">";
?>
Tu su obrazky: nove/text.png nove/mask.png
Namiesto tohoto:
$mask = imagecreatefrompng($mask_fname) or die ("chyba c.2");
$biela = imagecolorallocate ($mask, 255, 255, 255);
Treba pouzit toto
$mask = imagecreatefrompng($mask_fname) or die ("chyba c.2");
$docasna = imagecolorallocate ($mask, 0, 0, 0);
$biela = imagecolorallocate ($mask, 255, 255, 255);
Potom mozno ako transparentnu nastavit bielu lebo nebola alokovana ako prva