there is a php code to create a user defined text with specified font ( .ttf or .opf formats ) where it have a background image? i want to achieve a result like this sample ( creating the image dinamically with php )
-
why the hell this is downvoted!? i have a problem and i want a solution, duh. – AgelessEssence Oct 20 '14 at 07:54
-
http://stackoverflow.com/questions/7569885/overlay-image-with-text-and-convert-to-image – Arun Killu Oct 20 '14 at 07:54
-
2Because you have not shown any effort from your side – Arun Killu Oct 20 '14 at 07:56
-
@ArunKillu you clearly can't understand my question properly, the link you provied is not useful, i tried the code and it only put text into a new image. – AgelessEssence Oct 20 '14 at 08:10
-
@iim.hlk that doesn't explain what you have tried. For example, have you tried using common image libraries and perhaps found them too low-level to deal with, and now you're looking for easier alternatives? Or is it something else? – rr- Oct 20 '14 at 09:06
-
What have you tried? You have been a member for nearly 5 years, you should know that this is not an acceptable form of an SO question – Lemuel Botha Oct 20 '14 at 09:18
-
@LemuelBotha can you elaborate why? Sincerely I think I know the rules and I don't see any rule against this. I am totally bored by serial downvoters taht think SO should be the way they imagine. He is asking advice on how and what technology. His efforts have probably been on googling and searching rather than code. – FrancescoMM Jul 26 '17 at 13:53
-
@rr- what can he have tried if he is asking what technology we think he should start with? If this question is against rules, please provide the rule. – FrancescoMM Jul 26 '17 at 13:55
-
@ArunKillu clearly he doesn't know where to put his efforts on. That does not make the question an invalid candidate for SO (unless you cite the exact rule that forbids it). Users should show any effort they have tried: if there is no effort possible (because the question is before any possible effort) "any effort they have tried" is zero. So showing zero code is totally accepted. There is no rule saying questions with zero code are unacceptable. – FrancescoMM Jul 26 '17 at 14:00
-
@FrancescoMM I am by no means a "serial downvoter" and normally try to provide very helpful and elaborate exerts of code and a full explanation to try and assist other users. In the case of this question, he did not even mention what he had attempted to search what he found, what he thought he might try, etc. If he had been more elaborative, he would not be receiving the multiple downvotes. – Lemuel Botha Jul 27 '17 at 14:28
3 Answers
currently css can't do this without tricks and 100% cross-browser, the good alternative is svg

- 6,395
- 5
- 33
- 37
Provided you want to do it in PHP, not CSS (guessing from the question tags), you have two options:
- Using functions from
gd2
library. - Using functions from
ImageMagick
library.
While there might be code on the Internet that does the thing you asked for, most likely, they'll be essentially using either of these two libraries internally. Using these libraries yourself will enable you to create an image you exactly want.
The difference between these is that ImageMagick supports more formats and features at the expense of being less portable, while GD is installed on most systems, but it supports only JPG/PNG/GIF formats and provides few features.

- 14,303
- 6
- 45
- 67
I know this is an old question, but for those looking for something similar with GD... you have to deal with masks.
Like in this question:
PHP GD Use one image to mask another image, including transparency
The only difference is that the mask image will be built using type, by you, writing white on black (or black on white).
So you will need
- one input image for the background
- one input foreground image for the type
- one string "blabla" to type
- one intermediate new empty image to use as mask
- one new target image to output
Steps:
- create target image
- load background image
- copy background image on target image
- load foreground image
- create new image for mask (use same size of target or size of type)
- fill mask image with black
- type white string to mask image
copy foreground image to target image applying mask image as mask
output target image with correct mime type or save to disk

- 2,845
- 1
- 18
- 29