1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-18 04:12:00 +02:00

secure_image work.

This commit is contained in:
CaMer0n
2011-06-26 20:09:45 +00:00
parent af36a22695
commit db5c9726df
3 changed files with 140 additions and 136 deletions

View File

@@ -90,5 +90,131 @@ class secure_image
$code = $this->create_code();
return "<img src='".e_HTTP.$this->HANDLERS_DIRECTORY."secure_img_render.php?{$code}' class='icon secure-image' alt='' />";
}
/**
* Render the generated Image.
*/
function render()
{
$sql = e107::getDb();
$imgtypes = array('jpg'=>"jpeg",'png'=>"png",'gif'=>"gif");
$recnum = preg_replace("#\D#","",e_QUERY);
if($recnum == false){ exit; }
$sql->db_Select_gen("SELECT tmp_info FROM #tmp WHERE tmp_ip = '{$recnum}' LIMIT 1");
if(!$row = $sql->db_Fetch(MYSQL_ASSOC))
{
echo "Render Failed";
exit;
}
list($code, $url) = explode(",",$row['tmp_info']);
$type = "none";
foreach($imgtypes as $k=>$t)
{
if(function_exists("imagecreatefrom".$t))
{
$ext = ".".$k;
$type = $t;
break;
}
}
$path = e_IMAGE;
// TODO - add support for adding it in the THEME folder.
if(is_readable(e_IMAGE."secure_image_custom.php"))
{
require_once(e_IMAGE."secure_image_custom.php");
$bg_file = $secureimg['image'];
if(!is_readable(e_IMAGE.$secureimg['font']))
{
echo "Font missing"; // for debug only. translation not necessary.
exit;
}
if(!is_readable(e_IMAGE.$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);
}
ob_end_clean();
switch($type)
{
case "jpeg":
imagejpeg($image);
break;
case "png":
imagepng($image);
break;
case "gif":
imagegif($image);
break;
}
}
}
?>
?>