Show randomImage.php syntax highlighted
<?php
header("Content-Type: image/png; charset=UTF-8");
header("Vary: Accept");
// Encryption
require_once ('core/interface/encryption.php');
function loadXML($filename) {
if (strpos((string) $filename, ".") == 0)
$path= $filename;
else
$path= getcwd()."/".$filename;
if (false !== ($xml= simplexml_load_file((string) $path))) {
return $xml;
}
else {
exit ("ERROR Loading XML document located at: ".$path);
}
}
$xml= loadXML('config.xml');
if ((bool) $xml->encryption[0]->use_mcrypt) {
$cipher= $xml->encryption[0]->mcrypt_cipher;
require_once ('core/mcrypt.php');
}
else {
$cipher= $xml->encryption[0]->engine_cipher;
require_once ('core/'.$cipher.'.php');
}
$encryption= new Encryption($cipher, $xml->encryption[0]->key, $xml->encryption[0]->mode);
// /Encryption
$sessioncode= rand(123456, 999999);
setcookie("icode", $sessioncode);
$text= substr(strtoupper(md5($xml->encryption[0]->key.$sessioncode)), 0, 6);
// Save to session
// Generate image
$randomSpace= array ();
$totalSpaces= 0;
for ($i= 0; isset ($text[$i]); $i ++) {
$randomSpace[$i]= rand(0, 30);
$totalSpaces += $randomSpace[$i];
}
$font= imageloadfont("fonts/xtrusion.gdf");
$width= $totalSpaces +imagefontwidth($font) * strlen($text);
$height= imagefontheight($font);
$image= @ imagecreate($width +2, $height +2);
$bg= imagecolorallocate($image, 255, 255, 255);
imagecolortransparent($image, $bg);
for ($i= 0; $i < 2; $i ++) {
$color= imagecolorallocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
$x= rand(2, $width);
$y= rand(2, $height);
imagefilledellipse($image, $x, $y, $x * 2, $y * 2, $color);
}
$fontwidth= imagefontwidth($font);
$fontheight= imagefontheight($font);
$y= 0;
$totalSpaces= 0;
for ($i= 0; isset ($text[$i]); $i ++) {
$char= $text[$i];
$totalSpaces += $randomSpace[$i];
$x= $totalSpaces + $fontwidth * $i;
$color= imagecolorallocate($image, rand(150, 255), rand(150, 255), rand(150, 255));
imagestring($image, $font, $x, $y, $char, $color);
}
imagepng($image);
imagedestroy($image);
?>
See more files for this project here