Dynamische signature

Helpdesk & Vraag/Aanbod
Post Reply
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Dynamische signature

Post by Squizle »

Ik wil een signature gaan maken die elke keer veranderd.
Het gaat mij erop dat ik mooie quote's random kan afwisselen in mijn signature.

Ben aan het zoeken geweest naar dynamische signatures maar dan kom je al snel op die WoW signatures die laten zien hoe je game erbij staat en daar heb ik weinig aan.

Hoe kan ik zoiets realiseren?


P.S. Beetje het idee van JJapie zijn avatar en signature maar dan zonder de invoer mogelijkheid.
Namasté
JayBro
Posts: 482
Joined: 18 Apr 2005, 16:49
Location: Behind you
Contact:

Post by JayBro »

Dit is de mijne:

Ik heb "babelfish.ttf" en "avantgarde.ttf" in dezelfde map gezet.
En de volgende tabel in mn database

Code: Select all

CREATE TABLE `forum_sig` (
  `id` int(11) NOT NULL auto_increment,
  `sig` varchar(255) default NULL,
  `ip` varchar(16) default NULL,
  `host` varchar(255) default NULL,
  `date` int(15) NOT NULL default '0',
  KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
hierbij is ip,host en date niet echt nodig, dat was voor het invullen (zoals bij jjapie)

sig.php

Code: Select all

// eerst mysql database connecten
$link = mysql_connect("localhost", "naam", "ww");
mysql_select_db("db", $link);

//settings
$colors[0]  = "#EE9999";
$colors[1]  = "#99EE99";
$colors[2]  = "#9999EE";
$colors[3]  = "#EEEE99";
$colors[4]  = "#99EEEE";
$colors[5]  = "#EE99EE";
$fonts[0] = array("babelfish",18);
$fonts[4] = array("avantgarde",12);
$start_colour = "#EEEEEE";
$end_colour = "#CCCCCC";
$width = 350;
$height = 30;

//random font en grootte
srand ((float) microtime() * 10000000);
$fontNr = array_rand($fonts);
$fontFile   = "./".$fonts[$fontNr][0].".ttf";
$fontSize   = $fonts[$fontNr][1];

function parseColor($hex) {
	$r = substr($hex,1,2);
	$g = substr($hex,3,2);
	$b = substr($hex,5,2);
	return array(hexdec($r),hexdec($g),hexdec($b));
}

function getRandomColor() {
	global $colors, $im;

	srand ((float) microtime() * 10000000);
	$rand_keys = array_rand($colors);
	$color = $colors[$rand_keys];

	list($r,$g ,$b) = parseColor($color);
	return imagecolorallocate($im, $r, $g, $b);
}

// get signatures
$sql = "SELECT sig FROM forum_sig ORDER BY date DESC"; //LIMIT 10 OFFSET 0
$result = mysql_query($sql) or die ("Mysql error: ".mysql_error());

if(mysql_num_rows($result) > 0) {
	while($data = mysql_fetch_array($result)) {
		$sig[] = $data;
	}
}

// get random out of latest ten //
srand ((float) microtime() * 10000000);
$rand_key = array_rand($sig);
$sigText = $sig[$rand_key]['sig'];

// build image //
$im  = imagecreate($width, $height);
$bgc = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, $width, $height, $bgc);

// create fade
list($start_r,$start_g,$start_b) = parseColor($start_colour);
list($end_r,$end_g,$end_b) = parseColor($end_colour);

//LOOP THROUGH ALL THE PIXELS
for($y=0; $y < $height; $y++) {
	//CALCULATE THIS ROWS RGB COLOURS
  $new_r = $start_r - intval((($start_r - $end_r)/$height)*$y);
  $new_g = $start_g - intval((($start_g - $end_g)/$height)*$y);
  $new_b = $start_b - intval((($start_b - $end_b)/$height)*$y);

  //ALLOCATE THE COLOR
  $row_color = imagecolorresolve($im, $new_r, $new_g, $new_b);

	for($x=0; $x < $width; $x++) {
    //CREATE ROW OF THIS COLOR
    imagesetpixel($im, $x, $y, $row_color);
  }
}

// write text //
//imagestring($im, 5, 0, 0, $sigText, $color1);
list($r,$g,$b) = parseColor("#222222");
$color1 = imagecolorallocate($im,$r,$g,$b); //getRandomColor();
list($r,$g,$b) = parseColor("#BBBBBB");
$color3 = imagecolorallocate($im,$r,$g,$b);
$color2 = getRandomColor();

imagettftext($im, $fontSize, 0, 11, 26, $color3, $fontFile, $sigText);

imagettftext($im, $fontSize, 0, 6, 23, $color1, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 6, 21, $color1, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 4, 21, $color1, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 4, 23, $color1, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 5, 22, $color2, $fontFile, $sigText);

imagejpeg($im,"",98);
imagedestroy($im);
flush();
En dan gebruik je de volgende url in phpbb:

Code: Select all

[img]http://www.jaybro.nl/forum/sig.php/.png[/img]
Thats it :D
JJapie
General MOD
Posts: 4756
Joined: 14 Jun 2003, 23:02
Location: Huissen/Zeist
Contact:

Post by JJapie »

Dat kan simpeler:

sig.php

Code: Select all

$textfile = "sigs.txt";

srand((double)microtime()*1000000); 
$sigs=file($textfile); 
$nummer=rand(0, count($sigs)-1); 
$text = $sigs[$nummer];

$hoeveel = strlen($text); // hoeveel letters is de tekst?
$heigth = 18;

//width berekenen
$bbox = imagettfbbox( 12, 0, "Verdana.TTF", $text);
$bbwidth = ($bbox[4] - $bbox[6]);
$width = $bbwidth + 5;

mt_srand((double)microtime() * 1000000);                           //Maak nieuwe random getallen 

$nr1 = mt_rand(0, 254);                                            //Nummers voor kleur, random 
$nr2 = mt_rand(0, 254); 
$nr3 = mt_rand(0, 254); 

$im = ImageCreate($width, $heigth);
$bgcolor = imagecolorallocate ($im, 255, 255, 255); 
$textcolor = imagecolorallocate ($im, $nr1, $nr2, $nr3); 
ImageColorTransparent($im, $bgcolor);
imagettftext ($im, 12, 0, 0, 12, $textcolor, "Verdana.TTF", $text); 
header ("Content-type: image/png"); 
imagepng ($im); 
imagedestroy ($im); 
In sigs.txt zet je de quotes:

Code: Select all

Quote 1
quote 2
quote3
en verder moet je nog verdana.ttf in dezelfde map gooien (of een ander lettertype, maar dan moet je het script iets aanpassen).

That's all, lekker simpel, geen gedoe moet databases..
Last edited by JJapie on 15 Nov 2007, 21:12, edited 1 time in total.
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Post by Squizle »

ok thanks guys...ga er mee aan de slag

-edit-
Krijg foutmelding dat ie font niet kan openen
Heb de font netjes in folder van Signature gezet

Code: Select all

Warning: imagettfbbox(): Could not find/open font in /var/www/vhosts/squizle.nl/httpdocs/Signature/sig.php on line 13
P.S. JJapie, waarom maak je $hoeveel aan. zie die nergens terug komen.
Namasté
JJapie
General MOD
Posts: 4756
Joined: 14 Jun 2003, 23:02
Location: Huissen/Zeist
Contact:

Post by JJapie »

Je mist de font-file, download hier. (.edit: niet dus, niet goed gelezen) Bestandsnaam kan case-sensitive zijn, dus let daarop.

Het lijkt idd alsof ik met $hoeveel niks doe, denk dat die regel er nog staat van een vorige versie toen ik nog niet met imagettfbbox() werkte..
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Post by Squizle »

Ok..zit een foutje in het script.

Code: Select all

Parse error: syntax error, unexpected '}' in /var/www/vhosts/squizle.nl/httpdocs/Signature/sig.php on line 32
maar wanneer ik die } weg haal krijg ik deze melding:

Code: Select all

Warning: imagettfbbox(): Could not find/open font in /var/www/vhosts/squizle.nl/httpdocs/Signature/sig.php on line 13

Warning: imagettftext(): Could not find/open font in /var/www/vhosts/squizle.nl/httpdocs/Signature/sig.php on line 27

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/squizle.nl/httpdocs/Signature/sig.php:13) in /var/www/vhosts/squizle.nl/httpdocs/Signature/sig.php on line 28
�PNG  ��� IHDR����������r�����PLTE����Ñ
Namasté
JJapie
General MOD
Posts: 4756
Joined: 14 Jun 2003, 23:02
Location: Huissen/Zeist
Contact:

Post by JJapie »

nee, die } moet weg.. Ik heb dit stukje script uit mijn eigen signature-script geknipt maar niet helemaal zorgvuldig dus :X

Script werkt hier prima, dus er gaat echt iets mis bij jou. Nogmaals, klopt de naam van het font-bestand wel? Probeer het anders eens met de absolute-url (hoofdlettergevoelig!) naar het font-bestand.

Code: Select all

$font = "/var/www/vhosts/squizle.nl/httpdocs/Signature/verdana.ttf";
$bbox = imagettfbbox( 12, 0, $font, $text); 
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Post by Squizle »

nu werkt het wel. Zat hem dus toch in de naam van het font. Heb simpel verdana geprobeerd en tahoma. Met en zonder hoofdletters...alles...maar goed
nogmaals bedankt. Ga hem nu maar eens vullen :D

nu nog een andere vraag
graag zou ik de quote's met de volgende opmaak noteren
quote blaabla ••• auteur

hoe krijg ik dat erin? gewoon met html color tags in txt bestand werkt niet
Namasté
JJapie
General MOD
Posts: 4756
Joined: 14 Jun 2003, 23:02
Location: Huissen/Zeist
Contact:

Post by JJapie »

Ik heb hem even snel iets aangepast:

sig.php

Code: Select all

$textfile = "sigs.txt";

srand((double)microtime()*1000000);
$sigs=file($textfile);
$nummer=rand(0, count($sigs)-1);
$text = $sigs[$nummer];
$text = explode("|", $text);

$heigth = 18;

$width = array();

for($i=0;$i<3;$i++) //width berekenen per deel
{
 $bbox = imagettfbbox( 12, 0, "Verdana.TTF", $text[$i]);
 $bbwidth = ($bbox[4] - $bbox[6]);
 $width[$i] = $bbwidth + 5;	
}

$total_width = $width[0] + $width[1] + $width[2] + 10;

$im = ImageCreate($total_width, $heigth);
$bgcolor = imagecolorallocate ($im, 255, 255, 255);

$nr1 = array();
$nr2 = array();
$nr3 = array();
$textcolor = array();

for($i=0;$i<3;$i++) 
{
	mt_srand((double)microtime() * 1000000);                           //Maak nieuwe random getallen
	$nr1[$i] = mt_rand(0, 254);                                            //Nummers voor kleur, random
	$nr2[$i] = mt_rand(0, 254);
	$nr3[$i] = mt_rand(0, 254);
	$textcolor[$i] = imagecolorallocate ($im, $nr1[$i], $nr2[$i], $nr3[$i]);
}


ImageColorTransparent($im, $bgcolor);

imagettftext ($im, 12, 0, 0, 12, $textcolor[0], "Verdana.TTF", $text[0]);
imagettftext ($im, 12, 0, $width[0]+3, 12, $textcolor[1], "Verdana.TTF", $text[1]);
imagettftext ($im, 12, 0, $width[0]+3+$width[1]+3, 12, $textcolor[2], "Verdana.TTF", $text[2]);

header ("Content-type: image/png");
imagepng ($im);
imagedestroy ($im); 
sigs.txt

Code: Select all

een|twee|drie
vier|vijf|zes
zeven|acht|negen
[img:120:18]http://www.vandonselaar.eu/test/sig2.php/.png[/img]
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Post by Squizle »

dat werkt mooi...echter zou ik graag elke quote in precies dezelfde kleuren willen ;)
ben lastig, ik weet het...maar zou wel mooi zijn
Namasté
JJapie
General MOD
Posts: 4756
Joined: 14 Jun 2003, 23:02
Location: Huissen/Zeist
Contact:

Post by JJapie »

omdat ik gek ben

Code: Select all

$textfile = "sigs.txt";

srand((double)microtime()*1000000);
$sigs=file($textfile);
$nummer=rand(0, count($sigs)-1);
$text = $sigs[$nummer];
$text = explode("|", $text);

$heigth = 18;

$width = array();

for($i=0;$i<3;$i++) //width berekenen per deel
{
 $bbox = imagettfbbox( 12, 0, "Verdana.TTF", $text[$i]);
 $bbwidth = ($bbox[4] - $bbox[6]);
 $width[$i] = $bbwidth + 5;	
}

$total_width = $width[0] + $width[1] + $width[2] + 10;

$im = ImageCreate($total_width, $heigth);
$bgcolor = imagecolorallocate ($im, 255, 255, 255);

$color1r = "0";
$color1g = "128";
$color1b = "0";

$color2r = "255";
$color2g = "165";
$color2b = "0";

$color3r = "0";
$color3g = "0";
$color3b = "0";

$textcolor1 = imagecolorallocate ($im, $color1r, $color1g, $color1b);
$textcolor2 = imagecolorallocate ($im, $color2r, $color2g, $color2b);
$textcolor3 = imagecolorallocate ($im, $color3r, $color3g, $color3b);

ImageColorTransparent($im, $bgcolor);

imagettftext ($im, 12, 0, 0, 12, $textcolor1, "Verdana.TTF", $text[0]);
imagettftext ($im, 12, 0, $width[0]+3, 12, $textcolor2, "Verdana.TTF", $text[1]);
imagettftext ($im, 12, 0, $width[0]+3+$width[1]+3, 12, $textcolor3, "Verdana.TTF", $text[2]);

header ("Content-type: image/png");
imagepng ($im);
imagedestroy ($im);
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Post by Squizle »

dude je bent de beste...heel erg bedankt...
^:^ ^:^ ^:^
Namasté
JJapie
General MOD
Posts: 4756
Joined: 14 Jun 2003, 23:02
Location: Huissen/Zeist
Contact:

Post by JJapie »

:) Nu wil ik wel je eindresultaat zien straks :P
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Post by Squizle »

komt goed ;)...ben hem nu verder aan het vullen
zal vast ff eerste versie erop zetten :D

-edit- owja...sigs worden hier geresized |:(
Namasté
blimmel
Special MOD
Posts: 3049
Joined: 20 Jun 2003, 00:11
Location: Amersfoort

Post by blimmel »

<img src="http://www.squizle.nl/Signature/sig.php/.png">

Gaat prima, maar je moet een kleiner font of kortere quotes gebruiken. Je knoeit nu met de opmaak.

Kun je niet vanaf een bepaald aantal tekens een nieuwe regel doen? Of dat je dat zelf opgeeft in je text file (\n\r)?
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Post by Squizle »

Ben al op zoek naar kortere quote's. Heb de extreem langde nu verwijderd.
Snap nu ook waarom mijn sig geresized werd. Gebruikte [] ipv </>
Last edited by Squizle on 16 Nov 2007, 11:04, edited 1 time in total.
Namasté
JJapie
General MOD
Posts: 4756
Joined: 14 Jun 2003, 23:02
Location: Huissen/Zeist
Contact:

Post by JJapie »

Netjes hoor :p
JayBro
Posts: 482
Joined: 18 Apr 2005, 16:49
Location: Behind you
Contact:

Post by JayBro »

mja, dat kan ook :D

wel leuk gedaan zo :D
Squizle
Posts: 769
Joined: 21 Nov 2004, 23:54
Location: Lelystad
Contact:

Post by Squizle »

Thanks again. Ben er helemaal blij mee. Nu die lijst nog maar eens goed vullen. Heb er nog maar 18 in staan.
Namasté
Post Reply