Пример #1
0
 /**
  * Render the generated Image. Called without class2 environment (standalone).
  */
 function render($qcode)
 {
     require_once $this->BASE_DIR . $this->HANDLERS_DIRECTORY . "override_class.php";
     $over = new override();
     if ($user_func = $over->check($this, 'render')) {
         return call_user_func($user_func, $qcode);
     }
     if (!is_numeric($qcode)) {
         exit;
     }
     $recnum = preg_replace('#\\D#', "", $qcode);
     $imgtypes = array('jpg' => "jpeg", 'png' => "png", 'gif' => "gif");
     @mysql_connect($this->MYSQL_INFO['server'], $this->MYSQL_INFO['user'], $this->MYSQL_INFO['password']) || die('db connection failed');
     @mysql_select_db($this->MYSQL_INFO['db']);
     $result = mysql_query("SELECT tmp_info FROM {$this->MYSQL_INFO['prefix']}tmp WHERE tmp_ip = '{$recnum}'");
     if (!$result || !($row = mysql_fetch_array($result, MYSQL_ASSOC))) {
         // echo "Render Failed";
         // echo "SELECT tmp_info FROM {$this->MYSQL_INFO['prefix']}tmp WHERE tmp_ip = '{$recnum}'";
         exit;
     }
     $code = intval($row['tmp_info']);
     // new value
     $type = "none";
     foreach ($imgtypes as $k => $t) {
         if (function_exists("imagecreatefrom" . $t)) {
             $ext = "." . $k;
             $type = $t;
             break;
         }
     }
     $path = $this->BASE_DIR . $this->IMAGES_DIRECTORY;
     $secureimg = array();
     if (is_readable($path . "secure_image_custom.php")) {
         require_once $path . "secure_image_custom.php";
         /*   Example secure_image_custom.php file:
         
         			$secureimg['image'] = "code_bg_custom";  // filename excluding the .ext
         			$secureimg['size']	= "15";
         			$secureimg['angle']	= "0";
         			$secureimg['x']		= "6";
         			$secureimg['y']		= "22";
         			$secureimg['font'] 	= "imagecode.ttf";
         			$secureimg['color'] = "90,90,90"; // red,green,blue
         
         			*/
         $bg_file = $secureimg['image'];
         if (!is_readable($path . $secureimg['font'])) {
             echo "Font missing";
             // for debug only. translation not necessary.
             exit;
         }
         if (!is_readable($path . $secureimg['image'] . $ext)) {
             echo "Missing Background-Image: " . $secureimg['image'] . $ext;
             // for debug only. translation not necessary.
             exit;
         }
         // var_dump($secureimg);
     } else {
         $bg_file = "generic/code_bg";
     }
     switch ($type) {
         case "jpeg":
             $image = ImageCreateFromJPEG($path . $bg_file . ".jpg");
             break;
         case "png":
             $image = ImageCreateFromPNG($path . $bg_file . ".png");
             break;
         case "gif":
             $image = ImageCreateFromGIF($path . $bg_file . ".gif");
             break;
     }
     if (isset($secureimg['color'])) {
         $tmp = explode(",", $secureimg['color']);
         $text_color = ImageColorAllocate($image, $tmp[0], $tmp[1], $tmp[2]);
     } else {
         $text_color = ImageColorAllocate($image, 90, 90, 90);
     }
     header("Content-type: image/{$type}");
     if (isset($secureimg['font']) && is_readable($path . $secureimg['font'])) {
         imagettftext($image, $secureimg['size'], $secureimg['angle'], $secureimg['x'], $secureimg['y'], $text_color, $path . $secureimg['font'], $code);
     } else {
         imagestring($image, 5, 12, 2, $code, $text_color);
     }
     switch ($type) {
         case "jpeg":
             imagejpeg($image);
             break;
         case "png":
             imagepng($image);
             break;
         case "gif":
             imagegif($image);
             break;
     }
 }
Пример #2
0
 /**
  * Render the generated Image. Called without class2 environment (standalone).
  */
 function render($qcode, $color = '')
 {
     if ($color) {
         $this->FONT_COLOR = $this->hex2rgb($color);
     }
     //	echo "COLOR: ".$this->FONT_COLOR;
     require_once $this->BASE_DIR . $this->HANDLERS_DIRECTORY . "override_class.php";
     $over = new override();
     if ($user_func = $over->check($this, 'render')) {
         return call_user_func($user_func, $qcode);
     }
     if (!is_numeric($qcode)) {
         exit;
     }
     $recnum = preg_replace('#\\D#', "", $qcode);
     $imgtypes = array('png' => "png", 'gif' => "gif", 'jpg' => "jpeg");
     @mysql_connect($this->MYSQL_INFO['server'], $this->MYSQL_INFO['user'], $this->MYSQL_INFO['password']) || die('db connection failed');
     @mysql_select_db($this->MYSQL_INFO['db']);
     $result = mysql_query("SELECT tmp_info FROM {$this->MYSQL_INFO['prefix']}tmp WHERE tmp_ip = '{$recnum}'");
     if (!$result || !($row = mysql_fetch_array($result, MYSQL_ASSOC))) {
         // echo "Render Failed";
         // echo "SELECT tmp_info FROM {$this->MYSQL_INFO['prefix']}tmp WHERE tmp_ip = '{$recnum}'";
         exit;
     }
     $code = intval($row['tmp_info']);
     // new value
     $type = "none";
     foreach ($imgtypes as $k => $t) {
         if (function_exists("imagecreatefrom" . $t)) {
             $ext = "." . $k;
             $type = $t;
             break;
         }
     }
     $path = $this->BASE_DIR . $this->IMAGES_DIRECTORY;
     $fontpath = $this->BASE_DIR . $this->IMAGES_DIRECTORY;
     $secureimg = array();
     if (is_readable($path . "secure_image_custom.php")) {
         require_once $path . "secure_image_custom.php";
         /*   Example secure_image_custom.php file:
         
         			$secureimg['image'] = "code_bg_custom";  // filename excluding the .ext
         			$secureimg['size']	= "15";
         			$secureimg['angle']	= "0";
         			$secureimg['x']		= "6";
         			$secureimg['y']		= "22";
         			$secureimg['font'] 	= "imagecode.ttf";
         			$secureimg['color'] = "90,90,90"; // red,green,blue
         
         			*/
         // var_dump($secureimg);
         if (isset($secureimg['font']) && !is_readable($path . $secureimg['font'])) {
             echo "Font missing";
             // for debug only. translation not necessary.
             exit;
         }
         if (!is_readable($path . $secureimg['image'] . $ext)) {
             echo "Missing Background-Image: " . $secureimg['image'] . $ext;
             // for debug only. translation not necessary.
             exit;
         }
     } else {
         $fontpath = $this->BASE_DIR . $this->FONTS_DIRECTORY;
         $secureimg['image'] = "generic/code_bg";
         $secureimg['angle'] = "0";
         $secureimg['color'] = $this->FONT_COLOR;
         // red,green,blue
         $secureimg['x'] = "1";
         $secureimg['y'] = "21";
         $num = rand(1, 3);
         switch ($num) {
             case 1:
                 $secureimg['font'] = "chaostimes.ttf";
                 $secureimg['size'] = "19";
                 break;
             case 2:
                 $secureimg['font'] = "crazy_style.ttf";
                 $secureimg['size'] = "18";
                 break;
             case 3:
                 $secureimg['font'] = "puchakhonmagnifier3.ttf";
                 $secureimg['size'] = "19";
                 break;
         }
     }
     if (isset($secureimg['font']) && !is_readable($fontpath . $secureimg['font'])) {
         echo "Font missing";
         // for debug only. translation not necessary.
         exit;
     }
     if (isset($secureimg['image']) && !is_readable($path . $secureimg['image'] . $ext)) {
         echo "Missing Background-Image: " . $secureimg['image'] . $ext;
         // for debug only. translation not necessary.
         exit;
     }
     $bg_file = $secureimg['image'];
     switch ($type) {
         case "png":
             // preferred
             $image = imagecreatefrompng($path . $bg_file . ".png");
             imagealphablending($image, true);
             break;
         case "gif":
             $image = imagecreatefromgif($path . $bg_file . ".gif");
             imagealphablending($image, true);
             break;
         case "jpeg":
             $image = imagecreatefromjpeg($path . $bg_file . ".jpg");
             break;
     }
     // removing the black from the placeholder
     $image = $this->imageCreateTransparent(100, 35);
     //imagecreatetruecolor(100, 35);
     if (isset($secureimg['color'])) {
         $tmp = explode(",", $secureimg['color']);
         $text_color = imagecolorallocate($image, $tmp[0], $tmp[1], $tmp[2]);
     } else {
         $text_color = imagecolorallocate($image, 90, 90, 90);
     }
     header("Content-type: image/{$type}");
     if (isset($secureimg['font']) && is_readable($fontpath . $secureimg['font'])) {
         imagettftext($image, $secureimg['size'], $secureimg['angle'], $secureimg['x'], $secureimg['y'], $text_color, $fontpath . $secureimg['font'], $code);
     } else {
         imagestring($image, 5, 12, 2, $code, $text_color);
     }
     imagesavealpha($image, true);
     switch ($type) {
         case "jpeg":
             imagejpeg($image, null, 60);
             break;
         case "png":
             imagepng($image, null, 9);
             break;
         case "gif":
             imagegif($image);
             break;
     }
 }