{
    "mode": "perldoc",
    "parameter": "GD::Text::Align",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/GD%3A%3AText%3A%3AAlign/json",
    "generated": "2026-06-13T02:45:33Z",
    "synopsis": "use GD;\nuse GD::Text::Align;\nmy $gd = GD::Image->new(800,600);\n# allocate colours, do other things.\nmy $align = GD::Text::Align->new($gd\nvalign => 'top',\nhalign => 'right',\n);\n$align->setfont('arial', 12);\n$align->settext('some string');\n@bb = $align->boundingbox(200, 400, PI/3);\n# you can do things based on the bounding box here\n$align->draw(200, 400, PI/3);",
    "sections": {
        "NAME": {
            "content": "GD::Text::Align - Draw aligned strings\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use GD;\nuse GD::Text::Align;\n\nmy $gd = GD::Image->new(800,600);\n# allocate colours, do other things.\n\nmy $align = GD::Text::Align->new($gd\nvalign => 'top',\nhalign => 'right',\n);\n$align->setfont('arial', 12);\n$align->settext('some string');\n@bb = $align->boundingbox(200, 400, PI/3);\n# you can do things based on the bounding box here\n$align->draw(200, 400, PI/3);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "GD::Text::Align provides an object that draws a string aligned to a coordinate at an angle.\n\nFor builtin fonts only two angles are valid: 0 and PI/2. All other angles will be converted to\none of these two.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "This class inherits everything from GD::Text. I will only discuss the methods and attributes\nhere that are not discussed there, or that have a different interface or behaviour. Methods\ndirectly inherited include \"settext\" and \"setfont\".\n\nGD::Text::Align->new($gdobject, attrib => value, ...)\nCreate a new object. The first argument to new has to be a valid GD::Image object. The other\narguments will be passed on to the set method.\n\n$align->set(attrib => value, ...)\nSet an attribute. Valid attributes are the ones discussed in GD::Text and:\n\nvalign, halign\nVertical and horizontal alignment of the string. See also setvalign and sethalign.\n\ncolour, color\nSynonyms. The colour to use to draw the string. This should be the index of the colour in\nthe GD::Image object's palette. The default value is the last colour in the GD object's\npalette at the time of the creation of $align.\n\n$align->get(attribute)\nGet the value of an attribute. Valid attributes are all the attributes mentioned in GD::Text,\nthe attributes mentioned under the \"set\" method and\n\nx, y and angle\nThe x and y coordinate and the angle to be used. You can only do this after a call to the\ndraw or boundingbox methods. Note that these coordinates are not necessarily the same ones\nthat were passed in. Instead, they are the coordinates from where the GD methods will start\ndrawing. I doubt that this is very useful to anyone.\n\nNote that while you can set the colour with both 'color' and 'colour', you can only get it as\n'colour'. Sorry, but such is life in Australia.\n\n$align->setvalign(value)\nSet the vertical alignment of the string to one of 'top', 'center', 'base' or 'bottom'. For\nbuiltin fonts the last two are the same. The value 'base' denotes the baseline of a TrueType\nfont. Returns true on success, false on failure.\n\n$align->sethalign(value)\nSet the horizontal alignment of the string to one of 'left', 'center', or 'right'. Returns true\non success, false on failure.\n\n$align->setalign(valign, halign)\nSet the vertical and horizontal alignment. Just here for convenience. See also \"setvalign\" and\n\"sethalign\". Returns true on success, false on failure.\n\n$align->draw(x, y, angle)\nDraw the string at coordinates *x*, *y* at an angle *angle* in radians. The x and y coordinate\nbecome the pivot around which the string rotates.\n\nNote that for the builtin GD fonts the only two valid angles are 0 and PI/2.\n\nReturns the bounding box of the drawn string (see \"boundingbox()\").\n\n$align->boundingbox(x, y, angle)\nReturn the bounding box of the string to draw. This returns an eight-element list (exactly like\nthe GD::Image->stringTTF method):\n\n(x1,y1) lower left corner\n(x2,y2) lower right corner\n(x3,y3) upper right corner\n(x4,y4) upper left corner\n\nNote that upper, lower, left and right are relative to the string, not to the canvas.\n\nThe bounding box can be used to make decisions about whether to move the string or change the\nfont size prior to actually drawing the string.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "As with all Modules for Perl: Please stick to using the interface. If you try to fiddle too much\nwith knowledge of the internals of this module, you may get burned. I may change them at any\ntime.\n\nYou can only use TrueType fonts with version of GD > 1.20, and then only if compiled with\nsupport for this. If you attempt to do it anyway, you will get errors.\n\nIn the following, terms like 'top', 'upper', 'left' and the like are all relative to the string\nto be drawn, not to the canvas.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Any bugs inherited from GD::Text.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "copyright 1999 Martien Verbruggen (mgjv@comdyn.com.au)\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "GD, GD::Text, GD::Text::Wrap\n",
            "subsections": []
        }
    },
    "summary": "GD::Text::Align - Draw aligned strings",
    "flags": [],
    "examples": [],
    "see_also": []
}