2009-11-13 7 views
-1

Je souhaite créer un texte en tant que filigrane pour une image. la marque de l'eau doit avoir les propriétés suivantesTexte sous forme de filigrane en PHP

front: Impact 
color: white 
opacity: 31% 
Font style: regular, bold 
Bevel and Emboss 
size: 30 pixels 
+0

@jasim: vous avez posé une question à ce sujet il y a 10 minutes? voulez-vous éditer la dernière question? – RageZ

+1

@ non ce n'est pas pareil .. celui-ci est avec le texte et l'autre est avec une image png. – Andromeda

+0

@jasim: mon excuse pas de prob. – RageZ

Répondre

3

La documentation PHP est pas toujours si bon avec des exemples, mais dans ce cas, le imagefttext() docs devrait aider.

+1

mais est-il possible d'avoir des propriétés de biseau, de gaufrage, d'opacité pour cela? – Andromeda

0

utiliser la fonction d'opacité link.

<?php 

function filter_opacity(&$img, $opacity) //params: image resource id, opacity in percentage (eg. 80) 
{ 
if (!isset($opacity)) { 
    return false; 
} 
$opacity /= 100; 

//get image width and height 
$w = imagesx($img); 
$h = imagesy($img); 

//turn alpha blending off 
imagealphablending($img, false); 

//find the most opaque pixel in the image (the one with the smallest alpha value) 
$minalpha = 127; 
for ($x = 0; $x < $w; $x++) { 
    for ($y = 0; $y < $h; $y++) { 
     $alpha = (imagecolorat($img, $x, $y) >> 24) & 0xFF; 
     if ($alpha < $minalpha) { 
      $minalpha = $alpha; 
     } 
    } 
} 

//loop through image pixels and modify alpha for each 
for ($x = 0; $x < $w; $x++) { 
    for ($y = 0; $y < $h; $y++) { 
     //get current alpha value (represents the TANSPARENCY!) 
     $colorxy = imagecolorat($img, $x, $y); 
     $alpha = ($colorxy >> 24) & 0xFF; 
     //calculate new alpha 
     if ($minalpha !== 127) { 
      $alpha = 127 + 127 * $opacity * ($alpha - 127)/(127 - $minalpha); 
     } else { 
      $alpha += 127 * $opacity; 
     } 
     //get the color index with new alpha 
     $alphacolorxy = imagecolorallocatealpha($img, ($colorxy >> 16) & 0xFF, ($colorxy >> 8) & 0xFF, $colorxy & 0xFF, $alpha); 
     //set pixel with the new color + opacity 
     if (!imagesetpixel($img, $x, $y, $alphacolorxy)) { 
      return false; 
     } 
    } 
} 

return true; 

}

Exemple d'utilisation:

<?php 
$image = imagecreatefrompng("img.png"); 
filter_opacity($image, 75); 
header("content-type: image/png"); 
imagepng($image); 
imagedestroy($image); 
Questions connexes