|
|
#1 (permalink) |
|
Registered User
Join Date: Jan 2003
Location: UK
Posts: 928
|
PHP Script Problem
Hi all,
ive been trying to get a script working one that writes text onto an image but it doesnt, it just shows the image. http://www.colin-uk.com/scripts/capt...php?text=hello if you go to that url its ment to say "hello" on the sign heres the code im using: PHP Code:
thanks -c0lin
|
|
|
|
|
|
#2 (permalink) |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
1. it can be that PHP can't find the font you list (use absolute location or copy the ttf into the location the script also is (ie find out relative path)
2. the given x and y coordinates can be out of the image scope (don't know that since I'm too lazy to look up the image size) 3. This function requires both the GD library and the FreeType library. Make sure you have them both tip: destroy the image after sending it using imagedestroy($image);
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Jan 2003
Location: UK
Posts: 928
|
thanks for the reply greffov,
the font is in the same directory as the script so that shouldnt be a problem the GD image library is installed as i asked my host about it a few days ago, not sure about the freetype library though. will have to ask i,ll try changing the co-ordinates and see if that makes any diffrence. and thanks for the tip |
|
|
|
|
|
#4 (permalink) |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
maybe better start using the PHP example, and/or with coordinates 0,0 (top left corner)
Let us know if you get it to work!
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Join Date: Jan 2003
Location: UK
Posts: 928
|
Well i got it to work
See here but i have another question/problem now it works great for short words but, if i use long words then it goes off the edge of the image. is there anyway i can wrap it onto a new line? Click here for a long text example and can i stop the slanting of the text? it makes it look unrealistic lol thanks
|
|
|
|
|
|
#6 (permalink) |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
all nice and well, but couldn't you think of anything else like this?
About long lines... I really think you are to be creative there yourself. A possible approach would be defining the max characters that fit in the board, then split the text after each x characters, respecting word boundaries. That means if on char x is not a space you start looking backwards for the first space. If you can't find any, then just split on position x. suppose your max is 6, and your sentence is hello my name is collin, then the split would be: hello my name is collin But suppose your sentence was, hello I am rediculous, then the split would be: hello I am redicu lous The slanting is caused by the first argument (a 7), which defines the degrees of rotation. Do you ever RTFM? LOL
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
|
#7 (permalink) |
|
Registered User
Join Date: Jan 2003
Location: UK
Posts: 928
|
lol yeah i do RTFM
(i didnt know if it was just the font style lol) i found a function called wordwrap in the php manual but i dunno if i could use that some how... heres what i got so far PHP Code:
|
|
|
|
|
|
#8 (permalink) |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
hmmm, wait, I should rtfm too...
the first argument was the font size... array imagettftext ( resource image, int size, int angle, int x, int y, int color, string fontfile, string text) wordwrap sounds like a function that does what I described... cool, try and see what it does.
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
|
#11 (permalink) |
|
Registered User
Join Date: Jan 2003
Location: UK
Posts: 928
|
oops...
well i tried it with this code: PHP Code:
www.colin-uk.com/scripts/captions/familyguy.php?text=this is a very long sentence (copy and paste url) so word wrap doesnt seem to work then... Last edited by c0lin; 02-07-2004 at 12:38 PM. |
|
|
|
|
|
#12 (permalink) |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
LOL, colin, forgive me lauging, but... you are wordwrapping AFTER you made the image!!!
FIRST do the wordwrap (and use "\n" instead of "<br />", for we're not in HTML now), THEN generate the image, like: PHP Code:
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
|
#13 (permalink) |
|
Registered User
Join Date: Jan 2003
Location: UK
Posts: 928
|
i thought it was the imagepng command that made the image?
the php manual says the "\n" and "<br />" are the same so i just used that one i tried what u suggessted but now i just get a blank image with no text... |
|
|
|
|
|
#14 (permalink) |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
uhm, yes, you're right about the imagepng, but the imagettftext command draws the text in the image, which I referred to as 'make'.
I assume you only used my excerpt code. You needed all lines, but those two in that order. This is the complete code: PHP Code:
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|