Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Closed Thread
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-23-2012, 03:12 PM   PM User | #1
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
PHP and Image with GD library

I want to know the following aspects about GD library in PHP, so here my questions:

1/ I know we can write text in PHP on image using GD library. Can we rotate the text?

2/ Can we rotate an image or a text?

3/ Can we add shadow on the text?

4/ Can we move the text on any place on the image? I mean write the text anywhere on the image?

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?

Thank!

Last edited by angelali; 11-23-2012 at 03:18 PM..
angelali is offline  
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)
Old 11-23-2012, 04:46 PM   PM User | #3
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
The last question is important for me! Hope someone who knows will answer. Anyway thank you!
angelali is offline  
Old 11-30-2012, 05:54 AM   PM User | #4
c1lonewolf
Regular Coder

 
Join Date: Sep 2002
Posts: 216
Thanks: 0
Thanked 11 Times in 11 Posts
c1lonewolf is an unknown quantity at this point
Hi angelali,
Thyrosis did answer your last question. Sounds like you're slightly confused with the differences between a graphics library and graphics software.?
Quote:
The image created with GD is a static image, and cannot be edited
The GD Library is a set of functions for creating images on the fly much like your graphics software. The key difference is that with this library you have to create the tools to make it work where graphics software has done all the hard work for you. Both end up with a final static image.

As with these two function calls:
// 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+4 , int $y-4 , int $darkcolor , string $fontfile , string $text )

In graphics software each would be an object contained in another object say a 'Text' object. So you would use a form to change the text and an option to show a shadow or not. But the new object still has to be re-drawn for display.

Basically, you can create a graphics software package using the GD Library but you would also need to use something like javascript that would allow you to create new objects and drag n drop items etc. I had tried once before but didn't know how to send the info from js to php.
Anyway hope that helps...
__________________
NO Limits!!
c1lonewolf is offline  
Old 11-30-2012, 06:09 AM   PM User | #5
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
Well, the issue is, once you wrote something on the image from a textbox and click on abutton, it writes the text, but if you erase the textbox value and write again, it did not erase the text on the image as well. It is pixel based.
angelali is offline  
Old 11-30-2012, 06:11 PM   PM User | #6
c1lonewolf
Regular Coder

 
Join Date: Sep 2002
Posts: 216
Thanks: 0
Thanked 11 Times in 11 Posts
c1lonewolf is an unknown quantity at this point
Quote:
once you wrote something on the image from a textbox and click on abutton, it writes the text
exactly...

Quote:
but if you erase the textbox value and write again, it did not erase the text on the image.
Did you click on a button to re-draw the new image with the new text?

Process:
1. Enter string into textbox and click button.
2. Script wrote something on the image.
3. Script shows new textbox and button.
4. Change text in textbox and click button.
5. 2-5 repeats
__________________
NO Limits!!

Last edited by c1lonewolf; 11-30-2012 at 06:15 PM..
c1lonewolf is offline  
Old 11-30-2012, 06:13 PM   PM User | #7
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
I have already abandoned the project. thank you anyway.
angelali is offline  
Closed Thread

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:41 PM.


Advertisement
Log in to turn off these ads.