[GD Help] Rotate the Text with imagestring()

iam working on new project these days …

so, in a part of it it’s supposed to write on a picture …

i used imagettftext() to write it … and to rotate the text but
imagettftext() only use true type fonts … so it’s not anti-alised

imagestring() make nice font … but i can’t rotate it …

any ideas ? :rolleyes:

It’s kind of lame, but it works. Write in a new image, rotate it, then copy it back into your image.


$label = "Y-Axis Label";
$labelfont = 2;

// pixel-width of label
$txtsz = imagefontwidth($labelfont) * strlen($label);
// pixel-height of label
$txtht = imagefontheight($labelfont);

// define temp image
$labelimage = imagecreate($txtsz, $txtsz);
$white = imagecolorallocate($labelimage, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($labelimage, 0x00, 0x00, 0x00);

// write to the temp image
imagestring($labelimage, $labelfont, 0, $txtsz/2 - $txtht/2, $label , $black);

// rotate the temp image
$labelimage1 = imagerotate($labelimage, 90, $white);

// copy the temp image back to the real image
imagecopy($image, $labelimage1, 3, $vmargin + $ysize/2 - $txtsz/2, $txtsz/2 - $txtht/2, 0, $txtht, $txtsz);

// destroy temp images, clear memory