20. februar 2018 - 14:09
#5
Ok, hvis link ikke virker så er koden her:
<?php
session_start();
header("Content-type: image/jpeg");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$skrifttyper[] = "Arial.ttf";
$skrifttyper[] = "Tahoma.ttf";
$skrifttyper[] = "Impact.ttf";
$skrifttyper[] = "Verdana.ttf";
$skrifttyper[] = "Georgia.ttf";
$width=250;
$height=60;
$image = imagecreatetruecolor($width,$height);//Danner billedet
$y=0;$x=0;
for($i=0;$i<($width*$height);$i++)
{ $color = imagecolorallocate($image, mt_rand(155, 255), mt_rand(155, 255), mt_rand(155, 255));
imagesetpixel($image, ($x - 1), $y, $color);
$x += 1;
if($x >= $width)
{ $y += 1;
$x = 1;
}
}
$input='';
$tegn = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz";
for($i=0;$i<6;$i++)
{ $input.=substr($tegn, mt_rand(0, (strlen($tegn) - 1)), 1);
}
$_SESSION['security_code'] = $input;
$x = mt_rand(5, 35);//Startpunkt 10,$height
$y = mt_rand(35, 50);//Startpunkt 35,50
for($i=0;$i<strlen($input);$i++)
{ $color = imagecolorallocate($image, mt_rand(0, 155), mt_rand(0, 155), mt_rand(0, 155));
$font = "C:/Windows/Fonts/".$skrifttyper[mt_rand(0, (count($skrifttyper) - 1))];
imagettftext($image, mt_rand(25, 30), mt_rand(-10, 10), $x, $y, $color, $font, substr($input, $i, 1));
$x += mt_rand(25, 40);
$y += mt_rand(-5, 5);
}
for($i=0;$i<mt_rand(4, 6);$i++)
{ $color = imagecolorallocate($image, mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $width));
if(mt_rand(0, 2) == 1)
{ imageellipse($image, mt_rand(50,150), mt_rand(10, 50), mt_rand(10, $height), mt_rand(10, $height),$color);
}
else
{ imageline($image, mt_rand(0, 50), mt_rand(0, $height), mt_rand(100, $width), mt_rand(0, $height), $color);
}
}
for($i=0;$i<mt_rand(250, 500);$i++)
{ $color = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($image, mt_rand(0, $width), mt_rand(0, $height), $color);
}
imagejpeg($image);
ImageDestroy($image);
?>