Home | Forums | Articles | F@H
Help | Search | Members | Calendar | Forum Map | Cybervillage | Archive
Welcome Guest ( Log In | Register | Resend Validation Email )


>  IceTeks Forums -> Technology -> IceTeks Articles


Pages: (2) [1] 2   ( Go to first unread post ) Reply to this topicStart new topic

>  Making a dynamic text sig
Track this topic | Email this topic | Print this topic
Red Squirrel
Posted: Feb 6 2004, 08:24 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



Ever wonder how to make a sig that shows the viewer's IP or other info? This article will show you how, it's actually easier then you think, as long as you have a linux/apache host with php.

http://www.iceteks.com/articles.php?act=vi...cle=textsig&p=1


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Red Squirrel
Posted: Feb 7 2004, 02:05 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



I wanted to keep it simple so it's easier to understand so I did not include any fancy stuff. But there's a way to get it centred you need to first determine the side of the string and such. I did not try it myself though.

Chances are for the screen res you probably do need javascript but I'm sure php probably has a way of doing it too. I could be wrong though. I know there's more to the $_SERVER vars then IP, referrer and such. User agent is another bit of info that could be added but it's usually quite a long string of text. You'd want to have some if statements that check for specific things so if if says MSIE you can make it say "you use IE" and such.


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Red Squirrel
Posted: Jul 14 2004, 11:25 AM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



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. sad.gif But you should consider better hosting if they don't let you access to .htaccess.


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Red Squirrel
Posted: Aug 12 2004, 06:51 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



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. laugh.gif


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Red Squirrel
Posted: Aug 16 2004, 05:55 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



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&


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Red Squirrel
Posted: Aug 16 2004, 06:05 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



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.


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Streety
Posted: Aug 16 2004, 07:13 PM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 185
Member No.: 475
Joined: 16-August 04
Ice Cubes: 5



That's great. All working now.

Thanks! smile.gif


--------------------
user posted image
PMEmail Poster Top
larnu
Posted: Aug 25 2004, 05:49 AM
Quote Post

Icicle

Group Icon

Group: IceTeks Newbies
Posts: 6
Member No.: 480
Joined: 25-August 04
Ice Cubes: 0



just so u know, i';ve registered an account so i am e-mailed wen u reply know wink.gif
PMEmail Poster Top
larnu
Posted: Aug 26 2004, 07:44 AM
Quote Post

Icicle

Group Icon

Group: IceTeks Newbies
Posts: 6
Member No.: 480
Joined: 25-August 04
Ice Cubes: 0



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.
PMEmail Poster Top
Red Squirrel
Posted: Aug 26 2004, 05:51 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



With participation you get more priviliges such as longer edit limits so keep on participating and eventually you can edit any posts. Welcome aboard!


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
larnu
Posted: Aug 28 2004, 09:03 PM
Quote Post

Icicle

Group Icon

Group: IceTeks Newbies
Posts: 6
Member No.: 480
Joined: 25-August 04
Ice Cubes: 0



U didn't acutally answer ne of my question there btw, lol.
PMEmail Poster Top
Red Squirrel
Posted: Aug 28 2004, 11:06 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



I swear I must of answered it I remember but my post ain't there. laugh.gif I tend to stay up past 4:00am so maybe it was one of those moments where I just hit the X.


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.


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
larnu
Posted: Aug 29 2004, 02:40 PM
Quote Post

Icicle

Group Icon

Group: IceTeks Newbies
Posts: 6
Member No.: 480
Joined: 25-August 04
Ice Cubes: 0



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.
PMEmail Poster Top
larnu
Posted: Aug 29 2004, 03:12 PM
Quote Post

Icicle

Group Icon

Group: IceTeks Newbies
Posts: 6
Member No.: 480
Joined: 25-August 04
Ice Cubes: 0



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


This post has been edited by larnu on Aug 29 2004, 03:12 PM
PMEmail Poster Top
Red Squirrel
Posted: Aug 30 2004, 08:16 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



$px2=20
$py2=120

You forgot your semi colons.


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
larnu
Posted: Aug 30 2004, 08:19 PM
Quote Post

Icicle

Group Icon

Group: IceTeks Newbies
Posts: 6
Member No.: 480
Joined: 25-August 04
Ice Cubes: 0



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!
PMEmail Poster Top
Red Squirrel
Posted: Aug 30 2004, 08:31 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



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.


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Streety
Posted: Feb 23 2005, 03:23 PM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 185
Member No.: 475
Joined: 16-August 04
Ice Cubes: 5



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.

CODE

dynamic_sig
|
|
+--- .htaccess
|
|
+--- index.html
|
|
+--- official_sig.png
|
|
+--- text.txt


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.

CODE

<Files *.png>
     ForceType application/x-httpd-php
</Files>


official_sig.png is the dynamic signature image. It goes as follows.

CODE

<?php
// tell the user's browser that it is an image
header("Content-type: image/png");

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);



//Get quotes
$lines = file('text.txt');

//Count quotes
$num_quotes = count($lines);
$num_quotes_minus1 = $num_quotes - 1;

//Choose random quote
mt_srand((double)microtime()*1000000);
$quotes_choice = mt_rand(0, $num_quotes_minus1);
$text = $lines[$quotes_choice];
$text = trim($text);

//get the length of the string
$text_length = strlen($text);

//max line length is 65


//Create image
$lines_needed = $text_length / 65;
$lines_needed = ceil($lines_needed);
$height = $lines_needed * 17;

$image = @ImageCreate(500, $height)
  or die("Cannot Initialize new GD image stream");


//select random colors
mt_srand((double)microtime()*1000000);
$result = mt_rand(0, 5);


switch($result)
{
case 0:
$bg_color = imagecolorallocate($image, 0, 0, 0);//black
$text_color = imagecolorallocate($image, 255, 255, 255);//white
break;
case 1:
$bg_color = imagecolorallocate($image, 0, 0, 0);//black
$text_color = imagecolorallocate($image, 255, 0, 0);//red
break;
case 2:
$bg_color = imagecolorallocate($image, 0, 0, 0);//black
$text_color = imagecolorallocate($image, 0, 255, 0);//green
break;
case 3:
$bg_color = imagecolorallocate($image, 0, 0, 0);//black
$text_color = imagecolorallocate($image, 0, 255, 255);//blue
break;
case 4:
$bg_color = imagecolorallocate($image, 192, 192, 192);//grey
$text_color = imagecolorallocate($image, 0, 0, 0);//black
break;
case 5:
$bg_color = imagecolorallocate($image, 192, 192, 192);//grey
$text_color = imagecolorallocate($image, 0, 0, 255);//blue
break;
}



//apply background color
ImageFill($image, 0, 0, $bg_color);


//Break string up into words
$explode_text = explode(" ", $text);


//Re-construct the exploded string into lines
$line_length = 0;
$line = 0;
foreach ($explode_text as $token) {
$token_length = strlen($token);
$output_text[$line] .= $token;
$output_text[$line] .= " ";
$line_length = $line_length + $token_length + 1;
if ($line_length > 62){
 $line++;
 $line_length = 0;
}
}
   
// define the font, x_position
// how much the y_position changes (increments)
$font = 3;
$x_pos = 5;
$y_inc = 5;

$line_number = 1;


//Output each line to the image
$line_number = 1;
foreach ($output_text as $print)
{
   if ($line_number == 1) {$y_inc = 1;}
   else {$y_inc = 17;};
   
    imagestring($image, $font, $x_pos, "$y_inc * $line_number", $print, $text_color);
   $line_number++;
};



// Display the image
imagepng($image);
imagedestroy($image);
?>


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

CODE

. . . File not found. Should I fake it? (Y/N)
For any problem there is a solution that is simple, quick, and ultimately worse than the problem.
Hardware: The parts of a computer system that can be kicked.
If a train station is where the train stops, what is a work station?
I haven't lost my mind; it's backed up on tape somewhere.
Is reading in the bathroom considered Multi-Tasking?
It works! Now if only I could remember what I did...
To err is human, but to really foul things up requires a computer.
Will the information superhighway have any rest stops?
Never interrupt your opponent while he is making a mistake.
Life is like a roll of toilet paper . . . the closer you get to the end the faster it goes.
It is much easier to be critical than to be correct.
I have no problem keeping secrets. It's the people I tell...
Some people grin and bear it . . . others smile and change it.
The man who can smile when things go wrong has thought of someone else he can blame it on.
Acquaintance: a person whom we know well enough to borrow from, but not well enough to lend to.
Advice is what we ask for when we already know the answer but wish we didn't.
I couldn't repair your brakes, so I made your horn louder.
It's only funny until someone gets hurt. Then it's hilarious.
Lead me not into temptation. I can find it myself.
Never underestimate the power of stupid people in large groups.
The downside of being better than everyone else is that people tend to assume you're pretentious.
It is morally wrong to allow a sucker to keep his money.
Money can't buy you happiness, but it does bring you a more pleasant form of misery.
Many men would rather die than think.  Many do.


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. cool.gif

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.

user posted image

Obviously you'll need to refresh the page a few times to see it in its full glory. tongue.gif

Any question and I'll be happy to answer them. smile.gif


--------------------
user posted image
PMEmail Poster Top
Red Squirrel
Posted: Feb 23 2005, 05:43 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



That's pretty good. Probably simpler then the one in the article too. Horrible code in mine, I need to update it some day. em320.gif


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Streety
Posted: Feb 23 2005, 07:09 PM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 185
Member No.: 475
Joined: 16-August 04
Ice Cubes: 5



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.


--------------------
user posted image
PMEmail Poster Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | IceTeks Articles | Next Newest »

Topic Options Pages: (2) [1] 2  Reply to this topicStart new topic

 



[ Script Execution time: 0.0579 ]   [ 13 queries used ]   [ GZIP Enabled ]

< Home | Forums | Contact >