• Das Erstellen neuer Accounts wurde ausgesetzt. Bei berechtigtem Interesse bitte Kontaktaufnahme über die üblichen Wege. Beste Grüße der Admin

Rahmen um Schrift

Tectum

New member
Hy leute, wie kann ich einer Schrift einen rand geben,
also mit der GD-lib. Habe schon versucht die schrift mehrmals im hintergrund um ein paar pixel zu verschieben, oder mit größerem schriftgrad, aber dass sieht alles sch... aus :) keinnt jemand das Problem und hat ev eine gutaussehende Lösungsidee?
 
Möglich ist es auf jeden fall wie man bei http://www.promarkt.de/ bei den Preisen sieht.
Das img wird mit
Code:
http://www.promarkt.de/is-bin/INTERSHOP.enfinity/WFS/promarkt-DE-Site/de_DE/-/EUR/RenderImage-GetTextImage;pgid=F_xoH4fytLhSR0MrveKBL2gN0000htqM64Ln;sid=UoAfRWRWFZEfRSlht3YVBjuDxW_axvO5lwOIqqHVKs-45A==?TextToRender=39.99&StyleName=preis&ImageType=PNG
übergeben, man sieht dass der Preis übermittelt wird, wird also mit der GD-lib irgendwie gerandert, aber ich finde bei google absolut nix dazu :(
 
Geht schon... irgendwie... aber die GD-Bibliothek hat dafür nichts vorgefertigtes. Musst du hald slebst schreiben.
 
So falls es jemand auch mal braucht ;)

PHP:
<?php
$color1		= $_GET['color1'];
$color2		= $_GET['color2'];
$color3		= $_GET['color3'];
$color4		= $_GET['color4'];
$fontsize	= $_GET['s'];
$gettext	= $_GET['t'];
$getborder	= $_GET['b'];
$getwidth	= $_GET['w'];
$getheight	= $_GET['h'];

$r1			= hexdec(substr($color1, 0, 2));
$g1			= hexdec(substr($color1, 2, 2));
$b1			= hexdec(substr($color1, 4, 2));
$r2			= hexdec(substr($color2, 0, 2));
$g2			= hexdec(substr($color2, 2, 2));
$b2			= hexdec(substr($color2, 4, 2));
$r3			= hexdec(substr($color3, 0, 2));
$g3			= hexdec(substr($color3, 2, 2));
$b3			= hexdec(substr($color3, 4, 2));
$r4			= hexdec(substr($color4, 0, 2));
$g4			= hexdec(substr($color4, 2, 2));
$b4			= hexdec(substr($color4, 4, 2));

$font	= './fonts/arial.ttf';
$im		= imagecreatetruecolor($getwidth, $getheight);

imageantialias($im, true);

function imagettfborder($im, $size, $angle, $x, $y, $color, $font, $text, $width) {
	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);
	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);
	imagettftext($im, $size, $angle, $x-$width, $y, $color, $font, $text);
	imagettftext($im, $size, $angle, $x+$width, $y, $color, $font, $text);
	for ($i = 1; $i < $width; $i++) {
		imagettftext($im, $size, $angle, $x-$i, $y-$width, $color, $font, $text);
		imagettftext($im, $size, $angle, $x+$i, $y-$width, $color, $font, $text);
		imagettftext($im, $size, $angle, $x-$i, $y+$width, $color, $font, $text);
		imagettftext($im, $size, $angle, $x+$i, $y+$width, $color, $font, $text);
		imagettftext($im, $size, $angle, $x-$width, $y-$i, $color, $font, $text);
		imagettftext($im, $size, $angle, $x-$width, $y+$i, $color, $font, $text);
		imagettftext($im, $size, $angle, $x+$width, $y-$i, $color, $font, $text);
		imagettftext($im, $size, $angle, $x+$width, $y+$i, $color, $font, $text);
	}
}
$farbe1	= imagecolorallocate($im, $r1, $g1, $b1);
$farbe2	= imagecolorallocate($im, $r2, $g2, $b2);
$farbe3	= imagecolorallocate($im, $r3, $g3, $b3);
$farbe4	= imagecolorallocate($im, $r4, $g4, $b4);

imageFill($im, 0, 0, $farbe3);

if($color4!=""){imagettfborder($im, $fontsize, 0, $getborder*2, $fontsize+$getborder*2, $farbe4, $font, $gettext, $getborder+1);}
if($color2!=""){imagettfborder($im, $fontsize, 0, $getborder*2, $fontsize+$getborder*2, $farbe2, $font, $gettext, $getborder);}
imagettftext($im, $fontsize, 0, $getborder*2, $fontsize+$getborder*2, $farbe1, $font, $gettext);

header("Content-type: image/png");
imagePng($im);
imageDestroy($im);
?>
nicht die beste Lösung, aber es sieht halbwegs gut aus :D

PROBLEM:
Brauche den Text rechtsbündig, wie kann ich das realisieren wenn die textlängen unterschiedlich sind kann ich ja x & y nicht normal vom ursprung festsetzen, gibts da was in der lib, finde dazu nix
 
Zuletzt bearbeitet:
Auch das habe ich geschafft, habe die maße der schrift berechnet und das img dann rechtsbündig gemacht ;)

PHP:
$textwerte = imagettfbbox ($fontsize, 0, $font, $gettext);

$getwidth	= abs($textwerte[2]) + ($getborder+2)*2;
$getheight	= abs($textwerte[5]) + ($getborder+3)*2;

$im		= imagecreatetruecolor($getwidth, $getheight);
 
Zurück
Oben