![]() |
[PHP] wie ermittle ich die zeichen größe in einem image
hallo.
ich möchte gerne per php und den image...-functions ein bild erstellen, in dem ich ein zeichen/text ausgebe (das bild ist genau so groß wie der text/das zeichen) mit einem beliebigen winkel. wie kann ich denn (vorher) berechnen wie groß das zeichen/der text ist? ich weiß wohl, dass man das mit
Code:
macht, aber ich kriege
imagettfbbox
es echt nicht hih die höhe/breite des images und die x/y-koordinaten vorher richtig zu berechnen. ich habe auch schon im manual gelesen, dass diese funktion leicht buggy is und eine "gefixte" variante davon benutzt (die dort stand). das is also glaube ich nicht das problem. die ausgabe landet nie genau am oberen/linken rand und die größe stimmt glaube ich auch nicht (kann ich ja erst sehen, wenn die ausgabe genau positioniert ist). meine berechnung wird wohl einfach falsch sein, aber ich weiß echt nicht was ich falsch mache. mein test-code sieht so aus:
Code:
wobei laut manual die array-indexe von $b folgende bedeutung haben:
function imagettfbbox_t($size, $angle, $fontfile, $text)
{ // compute size with a zero angle $coords = imagettfbbox($size, 0, $fontfile, $text); // convert angle to radians $a = deg2rad($angle); // compute some usefull values $ca = cos($a); $sa = sin($a); $ret = array(); // perform transformations for($i = 0; $i < 7; $i += 2) { $ret[$i] = round($coords[$i] * $ca + $coords[$i+1] * $sa); $ret[$i+1] = round($coords[$i+1] * $ca - $coords[$i] * $sa); } return $ret; } $c = 'A'; $font = 'MSMINCHO.TTF'; $angle = rand(0, 30); $size = rand(22, 50); $r = 255; $g = 11; $b = 20; $b = imagettfbbox_t($size, $angel, $font, $c); $w = abs($b[6]) + abs($b[2]); $h = abs($b[1]) + abs($b[5]); $x = abs($b[6]) + abs($b[3]); $y = abs($b[5]) + abs($b[1]); $img = imagecreate ($w, $h); $bg = imagecolorallocate($img, 128, 128, 128); imagefill($img, 0, 0, $bg); $color = imagecolorallocate($img, $r, $g, $b); imagettftext($img, $size, $angle, $x, $y, $color, $font, $c); header("Content-type: image/png"); imagepng($img); imagedestroy($img);
Code:
mir raucht schon echt der kopf... wär sehr nett wenn mir da jmd helfen könnte!
0 untere linke Ecke, X-Position
1 untere linke Ecke, Y-Position 2 untere rechte Ecke, X-Position 3 untere rechte Ecke, Y-Position 4 obere rechte Ecke, X-Position 5 obere rechte Ecke, Y-Position 6 obere linke Ecke, X-Position 7 obere linke Ecke, Y-Position |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:06 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz