imagettftext und text stauchen?
DiamondDog
- php
0 ChrisB
Hallo Leute,
ich hab google schon bemüht aber nichts passendes dazu gefunden und zwar würde ich gerne den erzeugten Text auf meinem Bild stauchen. Weiß vll jemand wie ich das anstellen kann oder existiert vll irgend wo schon eine function die das kann die ich nicht gefunden habe?
So sieht mein Script aus:
<?php
require_once($_SERVER['DOCUMENT_ROOT']."/db_config.php");
$sql = mysql_query("SELECT * FROM anzahl");
function imagettfborder($im, $size, $angle, $x, $y, $color, $font, $text, $width) {
// top
imagettftext($im, $size, $angle, $x-$width, $y-$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x, $y-$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x+$width, $y-$width, $color, $font, $text);
// bottom
imagettftext($im, $size, $angle, $x-$width, $y+$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x, $y+$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x-$width, $y+$width, $color, $font, $text);
// left
imagettftext($im, $size, $angle, $x-$width, $y, $color, $font, $text);
// right
imagettftext($im, $size, $angle, $x+$width, $y, $color, $font, $text);
for ($i = 1; $i < $width; $i++) {
// top line
imagettftext($im, $size, $angle, $x-$i, $y-$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x+$i, $y-$width, $color, $font, $text);
// bottom line
imagettftext($im, $size, $angle, $x-$i, $y+$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x+$i, $y+$width, $color, $font, $text);
// left line
imagettftext($im, $size, $angle, $x-$width, $y-$i, $color, $font, $text);
imagettftext($im, $size, $angle, $x-$width, $y+$i, $color, $font, $text);
// right line
imagettftext($im, $size, $angle, $x+$width, $y-$i, $color, $font, $text);
imagettftext($im, $size, $angle, $x+$width, $y+$i, $color, $font, $text);
}
}
$strImage = $_SERVER['DOCUMENT_ROOT']."/xyz/abc/bild.png";
if( !file_exists( $strImage ) ) die("Das angegebene Bild existiert nicht!");
list ( $Image_Width, $Image_Height, $Image_Type ) = getimagesize ( $strImage );
$Image = imagecreatefrompng($strImage)
or die("Fehler bei imagecreatefrompng!");
$black = imagecolorallocate($Image, 0, 0, 0);
$white = imagecolorallocate($Image, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$grey = imagecolorallocate($im, 175, 175, 175);
$blue = imagecolorallocate($im, 0, 0, 255);
$ttf = $_SERVER['DOCUMENT_ROOT']."/xyz/abc/Fixedsys.ttf";
imagealphablending($Image, true);
imagesavealpha($Image, true);
$Schriftgröße = 40;
$Rotation = 0;
$text = ucfirst(str_replace("www.", "", $_SERVER['HTTP_HOST']));
$arr = imagettfbbox ( $Schriftgröße, $Rotation, $ttf, $text);
$x = ($Image_Width-($arr[2]-$arr[0]))/2;
$y = 40;
imagettfborder($Image, $Schriftgröße, $Rotation, $x+25, $y, $white, $ttf, $text, 1);
imagettftext ($Image, $Schriftgröße, $Rotation, $x+25, $y, $black, $ttf, $text);
$Schriftgröße = 22;
$Rotation = 0;
$text = "Anzahl ".floor(mysql_num_rows($sql))."!";
$arr = imagettfbbox ( $Schriftgröße, $Rotation, $ttf, $text);
$x = ($Image_Width-($arr[2]-$arr[0]))/2;
$y = 84;
imagettfborder($Image, $Schriftgröße, $Rotation, $x+35, $y, $white, $ttf, $text, 1);
imagettftext ($Image, $Schriftgröße, $Rotation, $x+35, $y, $black, $ttf, $text);
$Schriftgröße = 22;
$Rotation = 0;
$text = "Blabla.";
$arr = imagettfbbox ( $Schriftgröße, $Rotation, $ttf, $text);
$x = ($Image_Width-($arr[2]-$arr[0]))/2;
$y = 124;
imagettfborder($Image, $Schriftgröße, $Rotation, $x+35, $y, $white, $ttf, $text, 1);
imagettftext ($Image, $Schriftgröße, $Rotation, $x+35, $y, $black, $ttf, $text);
//Bildausgabe
header("Content-Type: image/png");
imagepng($Image);
imagedestroy($Image);
?>
Danke schon mal für eure Hilfe.
Mfg Dog
Hi,
ich hab google schon bemüht aber nichts passendes dazu gefunden und zwar würde ich gerne den erzeugten Text auf meinem Bild stauchen.
Text erst in ein neues, transparentes Bild schreiben, dieses dann gestaucht über das Zielbild drüber kopieren.
MfG ChrisB
Text erst in ein neues, transparentes Bild schreiben, dieses dann gestaucht über das Zielbild drüber kopieren.
Hey,
hab das jetzt mal Probiert stoß aber auf das Problem eine leere Grfik mit dem Text zu erzeugen und zwar wird nur die Textumrandung angezeigt nicht aber der Schwarzetext. Hast du da vll nen Tipp was da falsch ist?
Code:
<?php
...
$ttf = $_SERVER['DOCUMENT_ROOT']."/xyz/abc/Fixedsys.ttf";
imagealphablending($Image, true);
imagesavealpha($Image, true);
$Schriftgröße = 40;
$Rotation = 0;
$text = ucfirst(str_replace("www.", "", $_SERVER['HTTP_HOST']));
$arr = imagettfbbox ($Schriftgröße, $Rotation, $ttf, $text);
$x = ($Image_Width-($arr[2]-$arr[0]))/2;
$y = 40;
$Image_new = imagecreatetruecolor($Image_Width, $Image_Height);
imagettfborder($Image_new, $Schriftgröße, $Rotation, $x+25, $y, $white, $ttf, $text, 1);
imagettftext ($Image_new, $Schriftgröße, $Rotation, $x+25, $y, $black, $ttf, $text);
imagecolortransparent($Image_new, $grey);
...
?>