Jump to content

Php And Image With Gd Library


bunnyali2013

Recommended Posts

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!

Edited by bunnyali2013
Link to comment
Share on other sites

The function in GD for text is imagettftext

 

imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text );

 

1. Yes - third argument.

2. see 1. You can rotate image by transposing pixels from one position to another but no inbuilt function

3. No inbuilt function but you can print text in shadow colour then offset a couple of pixels and reprint in text colour.

4. Yes - specify the x,y postions (4th and 5th args above)

5. Reprint the text in same position but use background colour (eg white text on white background)

Link to comment
Share on other sites

The last question about editing is the most important. I will give you a little scenario where you can more understand.

 

Suppose I have an image, a textbox and a button. A user will write the text on the image by typing in the textbox then click on the button to write. Good.

 

Suppose now, after writing, the user saw he made a misspelling or simply want to clear the text to write another one. For that, he just simply use backspace to clear the previous text on the textbox, then write again, then click on the button to write on the image. I want to know will the previous text written on the image still be on the image or it will be edited according to the user's want?

 

Here is an example of a website:

 

http://yugico.com/yugioh-card-creator

 

Write a text, and click on the button. The text appears, good. But now, clear the textbox or simply edit the text and click on the button again, the text is edited. This is what I want to do.

 

I could use HTML5 canvas, but you cannot edit a written text or clear a text you wrote for another as it is pixel based. On canvas, you have to clear the whole canvas and start again.

Link to comment
Share on other sites

The function in GD for text is imagettftext

 

imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text );

 

1. Yes - third argument.

2. see 1. You can rotate image by transposing pixels from one position to another but no inbuilt function

3. No inbuilt function but you can print text in shadow colour then offset a couple of pixels and reprint in text colour.

4. Yes - specify the x,y postions (4th and 5th args above)

5. Reprint the text in same position but use background colour (eg white text on white background)

 

My apologies - correction to 2. above

 

Images can be rotated with imagerotate

 

resource imagerotate ( resource $image , float $angle , int $bgd_color [, int $ignore_transparent = 0 ] )

Link to comment
Share on other sites

Ok, this means we cannot do the change of text live. Ok, I thought a solution, I want you to tell me if it is good. Here is it below:

 

-On a page, there is the image, some textboxes and drop down list to write the text, choose fonts, size and position etc..and the button.

 

-All the textboxes and the button are in a form of course because there is a submit button. The image is outside the form.

 

-When the user will write a text in the textbox, select the color, font etc..., they will NOT appear on the image directly, but in fact, stored in a database in a table after clicking the button.

 

-After saving, the user will be redirected to another page to see the image with the text written on it. On this same page, there will be my codes to get the image from the page where the user has written the text, and also to get the texts stored in the database, to write it automatically on the image.

 

In the same line of thought, if the user has made a mistake or simply want to change the text as a whole, he/she has to return back on the page where to write the text, save it again to the database and redirect to the other page to see the image with the current texts updated.

 

Your opinion?

Edited by bunnyali2013
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.