View Single Post
Old 11-23-2012, 03:30 PM   PM User | #2
Thyrosis
New Coder

 
Join Date: Nov 2012
Posts: 72
Thanks: 4
Thanked 11 Times in 11 Posts
Thyrosis is on a distinguished road
1/ I know we can write text in PHP on image using GD library. Can we rotate the text?
Yes, you can. See http://php.net/manual/en/function.imagettftext.php for more information about the imagettftext function
PHP Code:
imagettftext resource $image float $size float $angle int $x int $y int $color string $fontfile string $text 
2/ Can we rotate an image or a text?
Yes, for images you can use http://www.php.net/manual/en/function.imagerotate.php

3/ Can we add shadow on the text?
Yes, just write the same text as in step 1, but then add or subtract a small number (depending on where you want the shadow to fall) to both x and y.
PHP Code:
// This will created some text with a dark shadow up-right from the original text
imagettftext resource $image float $size float $angle int $x int $y int $lightcolor string $fontfile string $text )
imagettftext resource $image float $size float $angle int $x+int $y-int $darkcolor string $fontfile string $text 
4/ Can we move the text on any place on the image? I mean write the text anywhere on the image?
Yes, use the x and y values from the function in step 1 to position the text anywhere on the canvas.

5/ On HTML5 Canvas, when you write a text,you cannot erase it as it is based on pixel. You have to clear the whole canvas and start again. I want to know if with GD library, can you clear a text if you have made a mistake and write another?
I'm not really sure what you mean with this question, but I think what you want is impossible with PHP alone. The image created with GD is a static image, and cannot be edited. The only thing you can do is, for instance if you want to change the text or position of the text on the image, is re-draw the image but edit the variables used. This is possibily best archieved by using some form of AJAX to avoid having to refresh the whole page, but I'll leave that up to you.

Hope that answers your questions =)

Regards,
Martin
Thyrosis is offline  
Users who have thanked Thyrosis for this post:
angelali (11-23-2012)