Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Nov 2012
    Posts
    115
    Thanks
    7
    Thanked 12 Times in 12 Posts
    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

  • Users who have thanked Thyrosis for this post:

    angelali (11-23-2012)

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    The last question is important for me! Hope someone who knows will answer. Anyway thank you!

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Posts
    456
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Hi angelali,
    Thyrosis did answer your last question. Sounds like you're slightly confused with the differences between a graphics library and graphics software.?
    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!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Sep 2002
    Posts
    456
    Thanks
    0
    Thanked 20 Times in 20 Posts
    once you wrote something on the image from a textbox and click on abutton, it writes the text
    exactly...

    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
    Last edited by c1lonewolf; 11-30-2012 at 06:15 PM.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    I have already abandoned the project. thank you anyway.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •