| Onykage - Jan-31-2006 server time | ||
There is a way to add the random factor without the read/write perms. Just use the rand() syntax. IE if you have 5 images then set something like the following:
in the php docs on php.net will explain the rest rand( min, max ); Also you can use the imagettftext syntaxt. This allows for a slightly more presice text insertion. PS. if you dont know already, to use a ttf font that font must be in the same dir as the php source file. |
| Cold Drink - Jul-18-2005 server time | ||
As a side note, that random text code is quite nasty. You could do this:
It is much easier to maintain this way, too. |
| Guest - Jul-18-2005 server time |
| I figured it out... my font was named Arial.ttf but in the code it was arial.ttf... can't believe i overlooked that. Lol anyway all is well now. Thank you very much. |
| Streety - Jul-18-2005 server time |
| Are both the arial.ttf file and omfghax.png in the same directory? I really don't know what to suggest. If your host is configured with the GD library I can see no reason why it wouldn't work. |
| Guest - Jul-18-2005 server time |
| I copied your entire code and pasted. Switched $im = imagecreatefrompng("wtf.jpg.png"); to $im = imagecreatefrompng("omfghax.png"); and it says cannot be displayed because of errors. I had to switch that cause i dont have that file... lol |
| Streety - Jul-18-2005 server time | ||||
Directory structure:
dynamic_pic_help_on_code.php:
Hope that helps. |
| Error - Jul-18-2005 server time |
| Can you paste your exact code... no matter what i do it says cannot be displayed. |
| Streety - Jul-18-2005 server time | ||||||||||||
The function imagestring only has the one preset but imagettftext is specifically for use with true type fonts. There are a couple of things with your code. When I tried to use it I got the following error
Looking at line 46 we have
For the variable px you used & rather than $. So if we fix that we get
After checking various things I came back to the same line. Alot of the variables are in the wrong places. It should be set out as below:
After you do all that you get this . . . I've changed the x and y values so it doesn't totally overlap your image (I couldn't be bothered making my own) but if you fix that one line it should work. One other thing to note though is that your random number isn't going to be very random. You need to seed the random number generator before you use it. The best way to do it is to include this code before you call the random number function;
I'm not sure why exactly this is the best way but I'm informed that it is. It certainly works though. |
| Error - Jul-17-2005 server time | ||
I can't get it to work... here is my code...
I do not really know any php so i was kinda guessing. |
| Red Squirrel - Jul-17-2005 server time |
| Actually arn't you limited to non true type fonts when using dynamic image text? I may be wrong though, never tried anything but default. |
| Streety - Jul-17-2005 server time |
| I'm glad you got it working. imagestring only has the one preset font. To use different fonts you will need to use imagettftext. It works in much the same way but if you have any questions just post them and I'll try and help. One piece of advice though; do a search for ttf fonts and come up with something more exciting than ariel. |
| Error - Jul-17-2005 server time | ||
| Sorry for the double post... Here is my image ![]() Here is my code.
how do i change the text to arial font? |
| Error - Jul-17-2005 server time |
| I got the one on the page working... but how do i change the font to arial? |
| Streety - Jul-17-2005 server time |
| Can you give me a little more information on your situation? It is all but impossible to help with what you have said so far. |
| Error - Jul-17-2005 server time |
| I see the background for the image but none of the quotes show up |
| Streety - May-28-2005 server time |
| Well most thngs are possible but that doesn't mean it's simple. There isn't a function that will automatically centre the text. You would need to calculate the length of the string being written to the image and then start half that distance away from the centre point. You can easily get the length of the string using strlen. You then need to multiply this number by the width of each character (this will vary depending on the font you use) to get the total length of the string. |
| Louis - May-28-2005 server time |
| Woould there be a way to make it so the text is centered in the image? Going along with the script that Streety wwrote i mean. |
| Streety - May-06-2005 server time |
| lol, that brings a whole new meaning to the online boyfriend quote as well! |
| Lightfeather - May-06-2005 server time |
| Yar. It's like sexual innuendo, inside joke, innuendo, something actually funny that popnfresh said, inside joke, etc etc I think my favorite so far is from our forum Bot. Anna is our forum Bot. Every now and then she just says something to crack me up. Most of the time she makes no sense at all but sometimes she'll drop a gem. Pax asked her "Do you look at pictures on the web?" and she replied, "Like tall, blond and sexy." Then pax asked, "Do you like tall, blonde, and sexy?" And her reply was submitted to the quotebot: "Some people like blonde and sexy. But I like airplanes." - Anna |
| Streety - May-06-2005 server time |
| A decent background is definitely an objective. I'll probably come back to this at some point and the background and matching up the height and line number are my two priorities. You should be able to stretch a background image to certain dimensions but I'm not sure how to do that as yet. You certainly have some interesting quotes there. |
| Lightfeather - May-06-2005 server time |
| I originally got interested in dynamic signatures because of this little goofy thing from sloganizer.net <a href="http://www.sloganizer.net/en/" target="_blank" title="Sloganizer - the slogan generator"><img src="http://www.sloganizer.net/en/style3,Lightfeather.png" border="0" alt="generated by sloganizer.net" title="This slogan was generated by sloganizer.net"/></a> You type in a word, select your background etc, and it randomly generates a "slogan" with your word and puts it behind a background. I run a gaming forum and over the years my friends have come up with some quotables that I've collected in a txt file and used to randomly generate a new quote on the index of the site. I thought it would be neat to have them randomly generate right in my signature =) Your code is what I was looking for. I would have wanted it on that nifty blue background but I don't see how I can get that image to conform to the ever changing size of the different quotes. I guess one way would be to have an image that fits the largest and just let it stay static but I like how the quotes only take up as much space as they need to. My labor of love: http://www.houseofgrog.com |
| Streety - May-06-2005 server time |
| No problem, I'm glad you pointed out there was a error. I'd love to see the finished result if you come back to the site again. |
| Lightfeather - May-06-2005 server time |
| Haha oh man! And I was staring at that for the longest time too. I changed the numbers to see what they'd do but it didn't seem to do anything. All for want of a negative sign. Thanks VERY much. It helped tremendously. |
| Streety - May-06-2005 server time | ||||
| We're all still learning, even (or perhaps especially) the people who like to sound as if they know what they are doing. The offending code is this:
It is in the last foreach of the code. If the line_number variable is 1 y_inc (the vertical distance from the top of the image) is 1. If it is anything else it is 17. A really quite stupid error but then they usually are. The correct code is this:
Just delete out the if statement and replace it with this. Now however many lines you have the lines should appear exactly 17 pixels below the previous line. An example using a longer piece of text is the following. ![]() I hope that helped. |
| Guest - May-06-2005 server time | ||
| I think it's here but I'm not that good with php to be able to make it work. It seems that if the line goes over 75 (I have mine set longer because my max width is 600 not 500) it is programed to make a new line... but nothing tells that new line to make a new line if it goes past 75 again.
I'm not even sure if that's really the problem. I'm still learning. |
| Streety - May-06-2005 server time |
| You're absolutely right. None of the quotes I use go to line 3 so I've never seen this problem before. The height of the image is handled seperately to the lines so I'm glad that part of the code is still working ok. I'll have a play around and see what the problem is. |
| Guest - May-06-2005 server time |
| I love your sig code streety! However I have an issue with quotes that are longer than two lines. All the words from lines 3 and on jumble up onto line two in a big overlapping mess. How can I fix it so that if the quote extends past 2 lines it won't buntch up? The hight of the actual graphic extends properly but all the words bunch up. |
| Streety - Feb-23-2005 server time |
| We can always improve our code. I would like to give it a more interesting background and fix the line issue but it just isn't worth it for the effort. It boosted my confidence and allowed me to tackle more challenging problems though so it has done its job. |
| Red Squirrel - Feb-23-2005 server time |
| That's pretty good. Probably simpler then the one in the article too. Horrible code in mine, I need to update it some day. |
| Streety - Feb-23-2005 server time | ||||||||
| It's been a while since I posted here but I managed to get my dynamic sig working a while back and now I'll share the code. Firstly, the files I have in my dynamic sig folder.
index.html is just a redirect to my website homepage. Nothing terribly complex or relevant there. .htaccess is there so that the png file is treated as php.
official_sig.png is the dynamic signature image. It goes as follows.
Hopefully the notes will help but I'll go into a little bit of detail at the end. text.txt is where I keep the text I want to display
Each quote is on a seperate line so that when I open the file it is broken up into an array. I wanted to update the list of quotes without updating my code so I first count how many quotes I have. Knowing that I'm able to pick one at random. The image is of a set width and I don't want my text running off the edge of the image so I break it up into lines. I originally did this by just chopping it up into strings of a arbitrary length but this didn't look good as words were broken up. Instead I broke the quote up into a series of words so I am able to reconstruct it up to a set length and then start on the next line. This means that no words are broken up and it just looks better. Obviously as the length of quotes changes so does the number of lines and hence the height of the image. This is again dedided on-the-fly. One problem with this code is that the height is not decided based on the number of lines but on the length of the quote divided by the maximum number of characters I want. This means that occasionally you get an extra line with no text on it. This was a throw back to the earlier version of this code that I never changed. Bigger and better projects and all that. Okay, so we've picked the quote, decided how many lines we want and hence how high the image wil be and then broken the quote down into lines. Between all this though is a switch statement. This just randomly chooses a set of colours for the text and background. I did consider randomly selecting colours but on consideration of the possible combinations decided against it. You could do it so you always get complimentary colours but I decided not to go that far. After that it is a simple case of constructing the image. All this gives the following final product. ![]() Obviously you'll need to refresh the page a few times to see it in its full glory. Any question and I'll be happy to answer them. |
| Red Squirrel - Aug-30-2004 server time |
| Our old host used to be like that (rcthost) so I switched to some private server host. If youc an find someone who offers private hosting it's the best way to go, and sometimes even cheaper then normal hosting. Only downside is that you don't exactly get support. I mean I can email the guy but I'm sure he does not want to start responding to everyone's questions and stuff since he's not an actual hosting company. Eventually I'd like to start my own hosting company, but I only want to do it if I can get my own servers and a cheap connection, I would not trust myself remotely managing servers since more things can go wrong. |
| larnu - Aug-30-2004 server time |
| Ahh yeah, tyvm, i can't test it now unfortunatly, my website is suffering a lot of down time as the server's crashed and i'm constantly going back in time on my website pages, it's really annoying! |
| Red Squirrel - Aug-30-2004 server time |
| $px2=20 $py2=120 You forgot your semi colons. |
| larnu - Aug-29-2004 server time |
| Argh i need edit, i double posting. Neway can u see what's wrong with this code? <?php header("Content-type: image/png"); $number = rand(1,5); if($number==1)$string2 = "I hope this works"; if($number==2)$string2 = "I hope this works well"; if($number==3)$string2 = "I hope this works really well"; if($number==4)$string2 = "I hope this works recon it will?"; if($number==5)$string2 = "I hope this works, i fink it mite"; if($number==1)$string4 = "This is string2"; if($number==2)$string4 = "This is string 2 again"; if($number==3)$string4 = "I wonder"; if($number==4)$string4 = "I hope it does"; if($number==5)$string4 = "i fink it will"; $im = imagecreatefrompng("http://www.dynamicsigs.larnu.co.uk/test.PNG"); $color = imagecolorallocate($im, 255, 255, 255); $color2 = imagecolorallocate($im, 0, 0, 0); $px=1; $py=50; $px2=20 $py2=120 imagestring($im, 3, $px, $py, $string, $color); imagestring($im, 2, $px, $py, $string2, $color); imagestring($im, 4, $px2, $py2, $string4, $color2); imagepng($im); imagedestroy($im); ?> I get this error Parse error: parse error, unexpected T_VARIABLE in /home/larnuc00/public_html/dynamicsigs/test.php on line 30 |
| larnu - Aug-29-2004 server time |
| I was so hoping it wasn't that, ok i gunna have a lot of work to do on that then, but i'll see if i can do it, i neva know i mite pull it off, i'll post my achievement on here to show u how i do. |
| Red Squirrel - Aug-28-2004 server time |
| I swear I must of answered it I remember but my post ain't there. Anyway, most of your questions are answered in the article. There's a variable to set the position of the text. imagestring($im, 3, $px, $py, $string, $color); $px and $py are the position Variables are unlimited, you can use the function like you would use echo() so you can replace $string with anything you like, including something with more then one variable. ex: $string = $var1." some text ".$var2 It's also possible to pull info off a site but it's more complex, since you also have to parse it. So if the info you want is in a table, you need to find that exact table, then get all the data in it. It all depends on the formatting of the web page and stuff, how you do it. I never really played with that myself so I can't really help you. But you can fopen() a http url then get all the data of the web page like you would if you read a file, but parsing it is the challenge. |
| larnu - Aug-28-2004 server time |
| U didn't acutally answer ne of my question there btw, lol. |
| Red Squirrel - Aug-26-2004 server time |
| With participation you get more priviliges such as longer edit limits so keep on participating and eventually you can edit any posts. Welcome aboard! |
| larnu - Aug-26-2004 server time |
| I can't edit a post, how stupid, i'll have to post again, if u tried e-mailing me it won't of worked caus my website is down, therefore reply to this post. |
| larnu - Aug-25-2004 server time |
| just so u know, i';ve registered an account so i am e-mailed wen u reply know |
| Guest - Aug-25-2004 server time |
| Can u answer my questions please, i wanna get on with it, and i don't like making my own code a lot, lol, it rarely works. |
| Larnu - Aug-20-2004 server time |
| Now i am going to be really annoying and ask a few questions, hopefully u can answer them. 1) How do i change the position of the text? 2) Can i have more than 1 variable? 3) Can i get information from another website, i.e. use a highscore table on a website and the text = the level. 4) Can i make other parts of the signature change becuase of a value, i.e. a target level and a bar at the bottom get's bigger the nearer the level is to the target. Can u answer all of those if you can and help me with coding if you can,. thanks a lot Larnu. P.S. if you need to e-mail me at admin@larnu.co.uk, i would appreciate it a lot. |
| Streety - Aug-16-2004 server time |
| That's great. All working now. Thanks! |
| Red Squirrel - Aug-16-2004 server time |
| That was weird. In the database there was a return somewhere for some reason so it messed up. Got rid of the return and boom, it worked! I should plug in a rtrim() in there somewhere to avoid this from hapening again. |
| Red Squirrel - Aug-16-2004 server time |
| Oh that's a different article... but that's really weird that it's doing that... Thanks for letting me know. It's acting as if it's not in the database, but it has to be since it shows up on the article list. I'll look into it, meanwhile just manually add page 2 in the url. P1: http://www.iceteks.com/articles.php?act=vi...cle=dynsig&p=1& P2: http://www.iceteks.com/articles.php?act=vi...cle=dynsig&p=2& |
| Streety - Aug-16-2004 server time |
| This is the link. There's just enough there to get you interested and then it stops. |
| Red Squirrel - Aug-12-2004 server time |
| can you give me a link to this article? Perhaps I accidentally put the wrong number in the db for the number of pages... but that's unlikely. Perhaps my conclusion just sucks and that it actually ended. |
| Streety - Aug-12-2004 server time |
| Hi You mention another article on dynamic sigs but when I went to view it only part of it appeared. I think I can figure out whats going on from this article but I would like to read the other article as well if possible. Is it possible to fix it? |
| Red Squirrel - Jul-14-2004 server time |
| unfortunatly not, since you need that php .jpg file to act as php and not as an image. Unless there's another way you can change the mime types for that folder, you're out of luck. |
| John - Jul-14-2004 server time |
| I dont have access to .htacess on this server, buts its got php and all, and I use it, is tehre any way to achieve this? |