001: 002: 003: 004: 005: 006: 007: 008: 009: 010: 011: 012: 013: 014: 015: 016: 017: 018: 019: 020: 021: 022: 023: 024: 025: 026: 027: 028: 029: 030: 031: 032: 033: 034: 035: 036: 037: 038: 039: 040: 041: 042: 043: 044: 045: 046: 047: 048: 049: 050: 051: 052: 053: 054: 055: 056: 057: 058: 059: 060: 061: 062: 063: 064: 065: 066: 067: 068: 069: 070: 071: 072: 073: 074: 075: 076: 077: 078: 079: 080: 081: 082: 083: 084: 085: 086: 087: 088: 089: 090: 091: 092: 093: 094: 095: 096: 097: 098: 099: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143:
|
<? if(!function_exists("imagettfbbox_bugfixed")){ function imagettfbbox_bugfixed($size, $angle, $fontfile, $text){ /** * Diese Funktion ist ein Workaround für das Fehlverhalten von ImageTTFBBox() bei gedrehten Texten. Der Fehler tritt mindestens bei * den PHP-Versionen 4.3.0 bis einschließlich 4.3.6 auf. * Der Workaround besteht darin, zunächst die Bounding Box für nicht gedrehten Text von der eingebauten Funktion zu erhalten und * das Ergebnis anschließend mit trigonometrischen Funktionen zu drehen. * Zusätzlich zur Standardfunktion werden die folgenden Werte im zurückgelieferten Array ergänzt: * 8: Größe des Textblocks in x-Richtung (Projektion auf die X-Achse) * 9: Größe des Textblocks in y-Richtung (Projektion auf die Y-Achse) * 10: Max. Ausdehnung des Textblocks in x-Ebene (Maximaler Abstand zwischen Punkten mit gleicher y-Koordinate) * 11: Max. Ausdehnung des Textblocks in y-Ebene (Maximaler Abstand zwischen Punkten mit gleicher x-Koordinate) * 12: kleinste X-koordinate * 13: kleinste Y-koordinate * 14: größte X-koordinate * 15: größte Y-koordinate */ $BBox_fixed = array();
/* Zunächst die eingebaute Funktion für den nicht gedrehten Text aufrufen: */ $BBox = imagettfbbox($size, 0, $fontfile, $text);
/* Sinus- und Cosinus bestimmen: */ $cos_angle = cos(deg2rad($angle)); $sin_angle = sin(deg2rad($angle));
/* Berechnung der maximalen Ausdehnung in x- und y-Ebene: */ $BBox_fixed[10] = ceil(($sin_angle == 0)? (NULL):(abs($BBox[1] - $BBox[7]) / $sin_angle)); $BBox_fixed[11] = ceil(($cos_angle == 0)? (NULL):(abs($BBox[1] - $BBox[7]) / $cos_angle));
/* Trigonometrische Umrechnung durchführen: */ for($i = 0; $i < 7; $i += 2) { $BBox_fixed[$i] = round($BBox[$i] * $cos_angle + $BBox[$i+1] * $sin_angle); $BBox_fixed[$i+1] = round($BBox[$i+1] * $cos_angle - $BBox[$i] * $sin_angle); }
/* Berechnung der Projektionsgröße in x- und y-Richtung: */ $BBox_xmin = min($BBox_fixed[0], $BBox_fixed[2], $BBox_fixed[4], $BBox_fixed[6]); $BBox_xmax = max($BBox_fixed[0], $BBox_fixed[2], $BBox_fixed[4], $BBox_fixed[6]); $BBox_ymin = min($BBox_fixed[1], $BBox_fixed[3], $BBox_fixed[5], $BBox_fixed[7]); $BBox_ymax = max($BBox_fixed[1], $BBox_fixed[3], $BBox_fixed[5], $BBox_fixed[7]); $BBox_fixed[8] = $BBox_xmax - $BBox_xmin; $BBox_fixed[9] = $BBox_ymax - $BBox_ymin; $BBox_fixed[12]=$BBox_xmin; $BBox_fixed[13]=$BBox_ymin; $BBox_fixed[14]=$BBox_xmax; $BBox_fixed[15]=$BBox_ymax;
ksort($BBox_fixed); return $BBox_fixed; } function hexrgb($hexstr, $rgb) { if(substr($hexstr,0,1)=="#"){ $hexstr=substr($hexstr,1); } $int = hexdec($hexstr); switch($rgb) { case "r": return 0xFF & $int >> 0x10; break; case "g": return 0xFF & ($int >> 0x8); break; case "b": return 0xFF & $int; break; default: $array= array( "r" => 0xFF & $int >> 0x10, "g" => 0xFF & ($int >> 0x8), "b" => 0xFF & $int ); $output=""; foreach($array as $key => $value){ $output.= intval($value).","; } return(substr($output,0,strlen($output)-1)); break; } } } $bildstring = $_GET['bildstring'] == '' ? "Bitte String angeben" : $_GET['bildstring']; $groesse = $_GET['groesse'] == '' ? 16 : $_GET['groesse']; $winkel = $_GET['winkel'] == '' ? 0 : $_GET['winkel']; $xoffset = $_GET['xoffset'] == '' ? 10 : $_GET['xoffset']; $yoffset = $_GET['yoffset'] == '' ? $groesse+5 : $_GET['yoffset']; $hgfarbe_get = $_GET['hgfarbe'] =='' ? 'ffffff' : $_GET['hgfarbe']; $schriftfarbe_get = $_GET['schriftfarbe'] =='' ? '000000' : $_GET['schriftfarbe']; $schattenfarbe_get = $_GET['schattenfarbe'] =='' ? 'cccccc' : $_GET['schattenfarbe']; $schatten = $_GET['schatten'] =='' ? 0:$_GET['schatten'];
$fontfile="fonts/arial.ttf"; $textConverted=str_replace("%20"," ",$bildstring); $sizeText=imagettfbbox_bugfixed ($groesse,$winkel,$fontfile,$textConverted);
$breite=$sizeText[8]+($xoffset*2); $hoehe=$sizeText[9]+($yoffset*2); //echo $breite."x".$hoehe."(".$sizeText[8]."x".$sizeText[9].")"; //print_r($sizeText); header("Content-type: image/jpeg");
$temp=imagecreatetruecolor($breite,$hoehe); //Verkleinertes Bild $black = ImageColorAllocate ($temp, 0, 0, 0);
$schriftfarbe = imagecolorallocate ($temp, hexrgb($schriftfarbe_get, r), hexrgb($schriftfarbe_get, g), hexrgb($schriftfarbe_get, b)); $schattenfarbe = imagecolorallocatealpha ($temp,0, hexrgb($schattenfarbe_get, r), hexrgb($schattenfarbe_get, g), hexrgb($schattenfarbe_get, b));
$fuellfarbe=imagecolorallocate($temp,hexrgb($hgfarbe_get, r), hexrgb($hgfarbe_get, g), hexrgb($hgfarbe_get, b)); imagefill($temp,0,0,$fuellfarbe);
if($sizeText[13]<0){ //$posy=$yoffset+$groesse; $posy=$sizeText[9]+$yoffset; }else{ //$posy=$sizeText[13]-$yoffset-$groesse; $posy=$sizeText[13]; }
if($sizeText[12]<0){ $pluswertx=$sizeText[12]*-1; $posx=$pluswertx+$xoffset; }else{ $posx=$sizeText[12]+$xoffset; }
if($schatten==1){ imagettftext($temp, $groesse, $winkel, $posx-round($groesse/15), $posy-round($groesse/15), $schattenfarbe, $fontfile,$bildstring); } imagettftext($temp, $groesse, $winkel, $posx, $posy , $schriftfarbe, $fontfile,$bildstring);
imagejpeg($temp,"",100);
?>
|