[vervolg]Gd geen error bji fout???
$tekst = sitemasters;
werkt gewoon, terwijl er geen ' ' om sitemasters staan?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
header("content-type: image/png");
$image = ImageCreate(82.5, 50); //Plaatje aanmaken met X=300 en Y=75
//We maken een achtergrondkleur
$achtergrond = ImageColorAllocate($image, 255, 255, 255); //255, 255, 255 = Wit
//De grootte van ons lettertype
$grootte = 12;
//Tekst die we op ons plaatje willen.
$tekst = sitemasters;
//Tekstkleur
$kleur = ImageColorAllocate($image, 255, 0, 0); //255, 0, 0 = Rood
//Het font selecteren, VERGEET DEZE NIET TE UPLOADEN !
$font = 'lucidaconsole.ttf';
//De functie word onder het voorbeeld uitgelegd!
ImageTTFText($image, $grootte, 0, 0, 25, $kleur, $font, $tekst);
//Het plaatje aanmaken.
ImagePng($image);
//Het plaatje verwijderen uit het geheugen
ImageDestroy($image);
?>
header("content-type: image/png");
$image = ImageCreate(82.5, 50); //Plaatje aanmaken met X=300 en Y=75
//We maken een achtergrondkleur
$achtergrond = ImageColorAllocate($image, 255, 255, 255); //255, 255, 255 = Wit
//De grootte van ons lettertype
$grootte = 12;
//Tekst die we op ons plaatje willen.
$tekst = sitemasters;
//Tekstkleur
$kleur = ImageColorAllocate($image, 255, 0, 0); //255, 0, 0 = Rood
//Het font selecteren, VERGEET DEZE NIET TE UPLOADEN !
$font = 'lucidaconsole.ttf';
//De functie word onder het voorbeeld uitgelegd!
ImageTTFText($image, $grootte, 0, 0, 25, $kleur, $font, $tekst);
//Het plaatje aanmaken.
ImagePng($image);
//Het plaatje verwijderen uit het geheugen
ImageDestroy($image);
?>
Gewijzigd op 01/01/1970 01:00:00 door Pepijn
Notice: Use of undefined constant sitemasters - assumed 'sitemasters' in
terug.
Dan heb je je error reporting uit staan, want normaal zou het wel een error geven. Neem maar eens iets met een spatie ertussen, dan geeft hij waarschijnlijk wel een error. PHP is aardig voor je, maar zo hoort het in ieder geval niet.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
error_reporting(E_ALL);
class mail2image {
public $color;
public $dir;
public function __construct($color, $dir) {
$this->color = explode(', ', $color);
$this->dir = $dir;
}
public function text($text) {
$text = explode(' ', $text);
foreach ($text as &$value) {
if(preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/', $value))
{
$this->gen_image($value);
$value = '<img src="'.$this->dir.sha1($value).'.png">';
}
}
return implode(' ', $text);
}
private function gen_image($mail) {
$font = imageloadfont('courier8.gdf');
$width = imagefontwidth($font)*strlen($mail);
$height = imagefontheight($font);
$image = imagecreatetruecolor($width, $height);
$trns = imagecolortransparent($image, imagecolorallocate($image, 0, 0, 0));
$color = imagecolorallocate($image, $this->color[0], $this->color[1], $this->color[2]);
imagefilledrectangle($image, 0, 0, $width, $height, $trns);
imagestring($image, $font, 0, 0, $mail, $color);
imagepng($image, $this->dir.sha1($mail).'.png');
imagedestroy($image);
}
}
$image = new mail2image('255, 0, 0', 'afbeelding/');
echo $image->text('[email protected] hallo ik ben pepijn hoe gaat het , dit is mijn domein naam pbogaard.nl [email protected] [email protected]');
?>
error_reporting(E_ALL);
class mail2image {
public $color;
public $dir;
public function __construct($color, $dir) {
$this->color = explode(', ', $color);
$this->dir = $dir;
}
public function text($text) {
$text = explode(' ', $text);
foreach ($text as &$value) {
if(preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/', $value))
{
$this->gen_image($value);
$value = '<img src="'.$this->dir.sha1($value).'.png">';
}
}
return implode(' ', $text);
}
private function gen_image($mail) {
$font = imageloadfont('courier8.gdf');
$width = imagefontwidth($font)*strlen($mail);
$height = imagefontheight($font);
$image = imagecreatetruecolor($width, $height);
$trns = imagecolortransparent($image, imagecolorallocate($image, 0, 0, 0));
$color = imagecolorallocate($image, $this->color[0], $this->color[1], $this->color[2]);
imagefilledrectangle($image, 0, 0, $width, $height, $trns);
imagestring($image, $font, 0, 0, $mail, $color);
imagepng($image, $this->dir.sha1($mail).'.png');
imagedestroy($image);
}
}
$image = new mail2image('255, 0, 0', 'afbeelding/');
echo $image->text('[email protected] hallo ik ben pepijn hoe gaat het , dit is mijn domein naam pbogaard.nl [email protected] [email protected]');
?>
Dit werkt uitstekend, alleen als ik zwarte tekst wil en dus
new mail2image('0,0,0', 'afbeelding/'); doe dan krijg ik geen geen tekst.
Hoe komt dit?
Mvg
Pepijn
Gewijzigd op 01/01/1970 01:00:00 door steen
Omdat je geen spaties tussen de komma's zet dan (bij 0,0,0). In je script staat dat er spaties tussen moeten zitten. Dan zou hij gewoon moeten werken...