You are here: Re: Need a simple database for name and email only « All PHP « IT news, forums, messages
Re: Need a simple database for name and email only

Posted by Steve on 03/24/07 21:56

security.inc.php creates a dynamic image with an overlay of text (i'm sure
you've seen this before). here's how it's done...


====== get.security.image.php

<?
require_once 'relative.path.php';
require_once $relativePath . 'site.cfg.php';
require_once $site->classDirectory . 'security.image.class.php';
$image = new securityImage($site->securityCode, $site->rootDirectory .
'images/security.image.jpg');
$image->create(securityImageConstants::PNG);
?>

======= security.image.class.php

<?
class securityImageConstants
{
const GD = 0;
const GIF = 1;
const JPG = 2;
const PNG = 3;
}

class securityImage
{
public $codeLength = 6;
public $accentColor = '990000';
public $fontColor = '990000';
public $fontSize = 48;
public $image = null;
public $securityCode = '';
public $securityImage = '';

private function __clone(){}

public function __construct($securityCode, $securityImage)
{
$this->securityCode = $securityCode;
$this->securityImage = $securityImage;
}

private function __copy(){}

public function create($type = securityImageConstants::PNG)
{
$imageSize = getimagesize($this->securityImage);
$this->image = imagecreatefromjpeg($this->securityImage);
$imageWidth = $imageSize[0];
$imageHeight = $imageSize[1];
$accentColor = imagecolorallocate(
$this->image
,
hexdec(substr($this->accentColor,
0, 2)) ,
hexdec(substr($this->accentColor,
2, 2)) ,
hexdec(substr($this->accentColor,
4, 2))
);
$fontColor = imagecolorallocate(
$this->image
,
hexdec(substr($this->fontColor,
0, 2)) ,
hexdec(substr($this->fontColor,
2, 2)) ,
hexdec(substr($this->fontColor,
4, 2))
);
$fontHeight = imagefontheight($this->fontSize);
$fontWidth = imagefontwidth($this->fontSize);
$text = substr(preg_replace('//', '$1 ',
$this->securityCode), 0, - 1);
$x = ($imageWidth - strlen($text) * $fontWidth) / 2;
$y = ($imageHeight - $fontHeight) / 2;
for ($i = 0; $i < strlen($text); $i++)
{
imagechar(
$this->image ,
$fontHeight ,
$x + ($fontWidth * $i) - 1 ,
$y ,
$text[$i] ,
$accentColor
);
imagechar(
$this->image ,
$fontHeight ,
$x + ($fontWidth * $i) ,
$y - 1 ,
$text[$i] ,
$fontColor
);
}
switch ($type)
{
case securityImageConstants::GD : imagegd($this->image) ; break;
case securityImageConstants::GIF : imagegif($this->image) ; break;
case securityImageConstants::JPG : imagejpeg($this->image) ; break;
default : imagepng($this->image) ; break;
}
imagedestroy($this->image);
}
}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация