http://qs1969.pair.com?node_id=11138848


in reply to Re^3: Centering Text with GD::Image
in thread Centering Text with GD::Image

I think this is the specific code that worked for me. There are a few weird things at the end because I am using EMBPERL. This is on a CentOS release 6.5 build.
use GD; $first = "First Name"; $middle = "Middle Name"; $last = "Last Name"; $image = "/www/images/image.jpg"; $im = GD::Image->newFromJpeg($image); ($width, $height) = $im->getBounds(); $outim = new GD::Image($width, $height); $outim->copyResampled($im, 0, 0, 0, 0, $width, $height, $width, $heigh +t); # name $fgcolor = $outim->colorAllocate(0,0,0); $fontname = '/usr/share/fonts/dejavu/DejaVuSerif.ttf'; $ptsize = 20; $angle = 0; $x = 345; $y = 275; $string = ucfirst($first) . ($middle ne '' ? ' ' . ucfirst($middle +) : '') . ' ' . ucfirst($last); @bounds = new GD::Image->stringFT($fgcolor,$fontname,$ptsize,$angle,$x +,$y,$string); $left = ($outim->width() / 2) - (($bounds[2] - $bounds[0]) / 2) + 5; $top = ($outim->height() / 2) - ($bounds[7] - $bounds[1]) / 2; $outim->stringFT($fgcolor, $fontname,$ptsize,$angle,$left,$y,$string); + # make sure we are writing to a binary stream binmode STDOUT; select(STDOUT); $| = 1; undef $/; $http_headers_out{'Content-Type'} = "image/png"; $escmode = 0; print OUT $outim->png();