|
|
|
| Добрый день. Имеется функция, которая создаёт картинку заданных размеров, распечатывает на ней произвольные цифры длиной 6 символов, и сохраняет полученное изображение в папку (капча на PHP). Необходимо подредактировать главную функцию таким образом, что бы картинка превратилась в анимацию (формат gif), и траектория движения символов была по оси OX, и была возможность контроля скорости передвижения. При чём символы должны на ~50% выежать за размеры картинки (т.е пропадать) в процессе передвижения по траектории.
function GenerateImage( $ImgWidth,$ImgHeight,$FontPath,$CacheDir )
{
$Code = rand( 100000,999999 );
$FontSize = $ImgHeight*0.75;
$ImgObj = @imagecreate( $ImgWidth, $ImgHeight ) or die( 'Cannot initialize new GD image stream!' );
$BackgroundColor = imagecolorallocate( $ImgObj, 255, 255, 255 );
$TextColor = imagecolorallocate( $ImgObj, 20, 40, 100 );
$NoiseColor = imagecolorallocate( $ImgObj, 100, 120, 180 );
$TextBox = imagettfbbox( $FontSize, 0, $FontPath, $Code ) or die( 'Error in imagettfbbox function!' );
$X = ($ImgWidth - $TextBox[4])/2;
$Y = ($ImgHeight - $TextBox[5])/2;
imagettftext( $ImgObj, $FontSize, 0, $X, $Y, $TextColor, $FontPath, $Code ) or die( 'Error in imagettftext function!' );
imagejpeg( $ImgObj,$CacheDir.DIRECTORY_SEPARATOR.session_id().'.jpg' );
imagedestroy( $ImgObj );
}
|
| |
|
|
|
|
|
|
|
для: pavluxa09
(10.05.2011 в 16:17)
| | Хм... мне кажется GDLib не самый удачный инструмент для реализации этой задумки. | |
|
|
|
|
|
|
|
для: cheops
(10.05.2011 в 17:26)
| |
$Width = 60;
$Height = 20;
$Font = './XeronEngine/Classes/CaptchaSecurity/CaptchaSecurity.ttf';
$Code = '123456';
$Delitel = 2;
$FontSize = $Height*0.75;
$FramesArr = array();
$FramesTimeArr = array();
$X = 0-($Width/2);
for( $i=0;$i<($Width*2)/$Delitel;$i++ )
{
$ImgObj = @imagecreate( $Width, $Height ) or die( 'Cannot initialize new GD image stream!' );
$BackgroundColor = imagecolorallocate( $ImgObj, 255, 255, 255 );
$TextColor = imagecolorallocate( $ImgObj, 20, 40, 100 );
$TextBox = imagettfbbox( $FontSize, 0, $Font, $Code ) or die( 'Error in imagettfbbox function!' );
if( $i<$Width/$Delitel )
$X+=$Delitel;
else
$X-=$Delitel;
$Y = ($Height - $TextBox[5])/2;
imagettftext( $ImgObj, $FontSize, 0, $X, $Y, $TextColor, $Font, $Code ) or die( 'Error in imagettftext function!' );
ob_start();
imagegif( $ImgObj );
$FramesArr[] = ob_get_clean();
$FramesTimeArr[] = 5;
}
$obj = new GIFEncoder( $FramesArr, $FramesTimeArr, 0, 2, 0, 0, 0, 0, 'bin');
Header ( 'Content-type:image/gif' );
echo $obj->GetAnimation ( );
|
| |
|
|
|
|