| | All rights reserved. | \*****************************************************************************/ # # $Id: elegant.php,v 1.0 2007/08/17 # if (!defined('XCART_START')) { header("Location: ../../"); die("Access denied"); } function wave($foreground_color, $background_color, $img, $width, $height) { $center = $width / 2; // periods $rand1=mt_rand(750000,1200000)/10000000; $rand2=mt_rand(750000,1200000)/10000000; $rand3=mt_rand(750000,1200000)/10000000; $rand4=mt_rand(750000,1200000)/10000000; // phases $rand5=mt_rand(0,3141592)/500000; $rand6=mt_rand(0,3141592)/500000; $rand7=mt_rand(0,3141592)/500000; $rand8=mt_rand(0,3141592)/500000; // amplitudes $rand9=mt_rand(330,420)/110; $rand10=mt_rand(330,450)/110; $img2 = imagecreatetruecolor($width - 10, $height + 21); $bgcolor = imagecolorallocate($img2, $background_color['red'], $background_color['green'], $background_color['blue']); imagefilledrectangle($img2, 0, 0, imagesx($img2), imagesy($img2), $bgcolor); for ($x = 0; $x < $width; $x++) { for ($y = -10; $y < $height + 20; $y++) { $sx = $x + (sin($x * $rand1 + $rand5) + sin($y * $rand3 + $rand6)) * $rand9 - $width / 2 + $center + 1 - 8; $sy = $y + (sin($x * $rand2 + $rand7) + sin($y * $rand4 + $rand8)) * $rand10; if ($sx < 0 || $sy < 0 || $sx >= $width - 1 || $sy >= $height - 1) { $color = 255; $color_x = 255; $color_y = 255; $color_xy = 255; } else { $color = imagecolorat($img, $sx, $sy) & 0xFF; $color_x = imagecolorat($img, $sx+1, $sy) & 0xFF; $color_y = imagecolorat($img, $sx, $sy+1) & 0xFF; $color_xy = imagecolorat($img, $sx+1, $sy+1) & 0xFF; } if($color == 0 && $color_x == 0 && $color_y == 0 && $color_xy == 0){ $newred = $foreground_color[0]; $newgreen = $foreground_color[1]; $newblue = $foreground_color[2]; } elseif ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255) { $newred = $background_color[0]; $newgreen = $background_color[1]; $newblue = $background_color[2]; } else { $frsx = $sx - floor($sx); $frsy = $sy - floor($sy); $frsx1 = 1 - $frsx; $frsy1 = 1 - $frsy; $newcolor = ( $color * $frsx1 * $frsy1 + $color_x * $frsx * $frsy1 + $color_y * $frsx1 * $frsy + $color_xy * $frsx * $frsy); if ($newcolor > 255) $newcolor = 255; $newcolor = $newcolor / 255; $newcolor0 = 1 - $newcolor; $newred = $newcolor0 * $foreground_color[0] + $newcolor * $background_color[0]; $newgreen = $newcolor0 * $foreground_color[1] + $newcolor * $background_color[1]; $newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2]; } imagesetpixel($img2, $x, $y + 10, imagecolorallocate($img2,$newred,$newgreen,$newblue)); } } return $img2; } # This function came from the phpcaptcha library. #Copyright (C) 2005-2007, Edward Eliot. #Copyright (C) 2007 Joan Bautista. function drawCharacters($code,$im,$width, $height) { global $characters; // loop through and write out selected number of characters $aFonts = array('fonts/LucidaBrightDemiBold.ttf','fonts/VeraBI.ttf','fonts/LucidaBrightItalic.ttf', 'fonts/Vera.ttf','fonts/VeraSe.ttf','fonts/VeraMono.ttf'); $iSpacing = (int)( $width / strlen($code)); for ($i = 0; $i < strlen($code); $i++) { // select random font $sCurrentFont = $aFonts[array_rand($aFonts)]; // select random colour $iRandColour = rand(0, 100); $iTextColour = imagecolorallocate($im, $iRandColour, $iRandColour, $iRandColour); // select random font size $iFontSize = rand(16,25); // select random angle $iAngle = rand(-30, 30); // get dimensions of character in selected font and text size $aCharDetails = imageftbbox($iFontSize, $iAngle, $sCurrentFont, $code[$i], array()); // calculate character starting coordinates $iX = $iSpacing / 4 + $i * $iSpacing; $iCharHeight = $aCharDetails[2] - $aCharDetails[5]; $iY = $heightt / 2 + $width / 4; // write text to image imagefttext($im, $iFontSize, $iAngle, $iX, $iY, $iTextColour, $sCurrentFont, $code[$i], array()); } return $im; } function draw_lines($im, $width, $height) { for ($i = 0; $i < 75; $i++) { // allocate colour $iRandColour = rand(100, 200); $iLineColour = imagecolorallocate($im, $iRandColour, $iRandColour, $iRandColour); // draw line imageline($im, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), $iLineColour); } return $im; } global $symbol_width; global $height; global $bCharShadow; $symbol_width = 30; $width = strlen($generation_str) * $symbol_width + 20; $height = 50; $code = $generation_str; $bCharShadow = false; $bg_color = array ('red' => 255, 'green' => 255, 'blue' => 255, 0 => 255, 1 => 255, 2 => 255 ); $text_color = array ( 'red' => 0, 'green' => 0, 'blue' => 0, 0 => 0, 1 => 0, 2 => 0 ); $im = imagecreate($width, $height); // allocate white background colour $bgcolor = imagecolorallocate($im, $bg_color['red'], $bg_color['green'], $bg_color['blue']); imagefilledrectangle($im, 0, 0, imagesx($im), imagesy($im), $bgcolor); $im = draw_lines($im, $width - 10, $height + 20); $im = drawCharacters($code,$im, $width, $height); #$im = wave($text_color,$bg_color, $im, $width, $height); header("Content-type:image/png"); imagepng($im); imagedestroy($im); ?>