GD Rotate not working

Im trying to simply rotate some text by 15 degrees, but I cant get it working at all despite multiple debug lines

My simplified code I dont think I could get more simpler, what Ive done is:-

<?php
header('Content-Type: image/png');

$im = imagecreatetruecolor(300, 150);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

imagefilledrectangle($im, 0, 0, 300, 150, $white);

$text = 'Testing...';
$font = 'arial.ttf';

imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

imagerotate($im, 15, 0);

imagepng($im);
imagedestroy($im);
?>

Open in new window


Any idea what Im doing wrong?
tonelm54Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Your first problem is most likely your font file. The path to the font file needs to be the absolute path if the .ttf is not in the same folder as your script.

This will get you an image but it won't be rotated. This is because imagerotate returns a resource handle to the rotated image. You have to use that return value in your imagepng call - and then destroy that handle as well.

Sample code here (with arial.ttf in same folder as script).
<?php
header('Content-Type: image/png');

$im = imagecreatetruecolor(400, 150);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

imagefilledrectangle($im, 0, 0, 399, 149, $white);

$text = 'Testing...';
$font = 'arial.ttf';

imagettftext($im, 20, 0, 11, 21, $black, $font, $text);

$rotate = imagerotate($im, 15, 0);

imagepng($rotate);
imagedestroy($im);
imagedestroy($rotate);

Open in new window

Working sample here http://www.marcorpsa.com/ee/t789.php
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
No points for this, please, but when in doubt it's always wise to check the online man pages.  I could not work without a window open to PHP.net at all times.  In the instant case you can see that the imagerotate() function returns a resource.
http://php.net/manual/en/function.imagerotate.php

I can see how this can be confusing, since many of the other image functions mutate a resource and return something like a boolean, but that is the unfortunate nature of PHP - it's hard to guess what will be changed or returned without reference to the manual.  Example of a related function:
http://php.net/manual/en/function.imagesetinterpolation.php
0
Vimal DMSenior Software EngineerCommented:
Hi,

Try installing "imagick" and restarted apache.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.