bunnyali2013 Posted November 23, 2012 Share Posted November 23, 2012 (edited) 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 November 23, 2012 by bunnyali2013 Quote Link to comment https://forums.phpfreaks.com/topic/271076-php-and-image-with-gd-library/ Share on other sites More sharing options...
Barand Posted November 24, 2012 Share Posted November 24, 2012 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) Quote Link to comment https://forums.phpfreaks.com/topic/271076-php-and-image-with-gd-library/#findComment-1394722 Share on other sites More sharing options...
bunnyali2013 Posted November 24, 2012 Author Share Posted November 24, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271076-php-and-image-with-gd-library/#findComment-1394724 Share on other sites More sharing options...
Barand Posted November 24, 2012 Share Posted November 24, 2012 If you are putting text on a complex background, such as a photograph, you would need to reload the image and print the revised text. Quote Link to comment https://forums.phpfreaks.com/topic/271076-php-and-image-with-gd-library/#findComment-1394729 Share on other sites More sharing options...
Barand Posted November 24, 2012 Share Posted November 24, 2012 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 ] ) Quote Link to comment https://forums.phpfreaks.com/topic/271076-php-and-image-with-gd-library/#findComment-1394737 Share on other sites More sharing options...
bunnyali2013 Posted November 24, 2012 Author Share Posted November 24, 2012 (edited) 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 November 24, 2012 by bunnyali2013 Quote Link to comment https://forums.phpfreaks.com/topic/271076-php-and-image-with-gd-library/#findComment-1394739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.