in reply to Re: Centering Text with GD::Image
in thread Centering Text with GD::Image
G'day Bod,
I recall this (or very similar) code from various questions you were asking some months ago. In isolation, this could be quite confusing; consider labelling it as an extract and then adding a link back to the original code to provide more context. However, that's the least of my issues with your post.
Of far greater concern, is posting code like:
new GD::Image->stringFT(...)
Please read "perlobj: Invoking Class Methods" in general; and specifically the "Indirect Object Syntax" subsection. Note the emboldened "use of this syntax is discouraged"; and later "We recommend that you avoid this syntax". Reasons are given later in that subsection.
I don't recall your original code in any detail which makes suggesting an absolute fix impossible. Maybe replace both lines with something closer to:
GD::Image::->new()->stringFT(...)
Or perhaps create one generic, reuseable object:
my $generic_gd_img = GD::Image::->new(); $generic_gd_img->stringFT(...)
There's potentially other ways to handle this, such as returning @bounds from a subroutine; however, please avoid the indirect syntax in your own code and don't suggest its use to others.
— Ken