It seems to be extensive but it is necessary to get to the idea.
I am developing a captcha image one of my ideas was to model a captcha image similar to google text captcha.
I have not been able to create the same style but I have generated a somewhat similar captcha image and I think it is more original for my own system.
I generate the text of the image in this way:
imagettftext($image,25,mt_rand(-40,30),10,30,$black,"resources/fonts/font.ttf",$first); //tamaño de la fuente se realiza en la primera numeración(25)
imagettftext($image,25,mt_rand(-40,30),30,30,$black,"resources/fonts/font1.ttf",$second); //giro de la fuente se realiza en la segunda y tercera numeración (-40,30)
imagettftext($image,25,mt_rand(-40,30),50,30,$black,"resources/fonts/font2.ttf",$third); // Espacio la cuarta, alto la quinta (50,30)
imagettftext($image,25,mt_rand(-40,30),70,30,$black,"resources/fonts/font3.ttf",$fourth); // se puede cambiar varios modelo de fuente
For a more ordered and optimized code try to implement an array but the image did not load.
$fonts = array(
'font' => array('spacing' => -3, 'minSize' => 27, 'maxSize' => 30, 'font' => 'resources/fonts/font.ttf'),
'font1' => array('spacing' =>-1.5,'minSize' => 28, 'maxSize' => 31, 'font' => 'resources/fonts/font1.ttf'),
'font2' => array('spacing' => -2, 'minSize' => 24, 'maxSize' => 30, 'font' => 'resources/fonts/font2.ttf'),
'font3' => array('spacing' => -2, 'minSize' => 30, 'maxSize' => 38, 'font' => 'resources/fonts/font3.ttf'),
'font4' => array('spacing' => -2, 'minSize' => 24, 'maxSize' => 34, 'font' => 'resources/fonts/font4.ttf'),
'font5' => array('spacing' => -2, 'minSize' => 28, 'maxSize' => 32, 'font' => 'resources/fonts/font5.ttf'),
'font6' => array('spacing' =>-1.5,'minSize' => 28, 'maxSize' => 32, 'font' => 'resources/fonts/font6.ttf'),
'font7' => array('spacing' => -2, 'minSize' => 28, 'maxSize' => 34, 'font' => 'resources/fonts/font7.ttf'),
'font8' => array('spacing' => -1, 'minSize' => 20, 'maxSize' => 28, 'font' => 'resources/fonts/font8.ttf'),
);
The font color, a different color for each page update:
$black = imagecolorallocate($image,rand(78,181),rand(163,35),rand(36,7));
The problem with this parameter is that getting the color to my liking with an array would be much better, but I had the same problem as before.
$black = array(
array(17,70,121),
array(12,133,25),
array(114,26,7),
array(38,44,10),
array(16,113,52),
array(123,29,26)
);
The background color of the image is white.
$white = imagecolorallocate($image,255,255,255);
I don't know if it's possible to create a transparent background color by adding a variation of a rgba
.
rgba(82, 56, 76, 0.15);
Thus:
imagecolorallocate($image,82, 56, 76, 0.15);
does not print the image.
Analyzing the different types of captcha on the web I have observed in some captcha where the text of the image is personalized, this is due to .txt
personalized libraries where the file .txt
has different personalized text used as text of the captcha image.
Unlike a random image:
$source = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
It would be useful to be able to replace a random text to a custom text using libraries.txt
My captcha code in the current layout captcha.php .
<?php
session_start();
$image = imagecreatetruecolor(120,50); //Ancho y alto de la imagen
$white = imagecolorallocate($image,255,255,255); // Color de fondo de la imagen
$black = imagecolorallocate($image,rand(78,181),rand(163,35),rand(36,7)); //Cambio de color de la fuente al refrescar
imagefill($image,0,0,$white);
imagerectangle($image,1,1,99,39 ,$white); // Configura el color del marco
$source = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$first = $source[mt_rand(0,61)];
$second = $source[mt_rand(0,61)];
$third = $source[mt_rand(0,61)];
$fourth = $source[mt_rand(0,61)];
$_SESSION['captcha_secure'] = $first.$second.$third.$fourth;
imagettftext($image,25,mt_rand(-40,30),10,30,$black,"resources/fonts/Quixley.ttf",$first); //tamaño de la fuente se realiza en la primera numeracion -> (25)
imagettftext($image,25,mt_rand(-40,30),30,30,$black,"resources/fonts/AntykwaBold.ttf",$second); //giro de la fuente se realiza en la segunda y tercera numeración -> (-40,30)
imagettftext($image,25,mt_rand(-40,30),50,30,$black,"resources/fonts/Ding-DongDaddyO.ttf",$third); // Espacio la cuarta, alto la quinta -> (50,30)
imagettftext($image,25,mt_rand(-40,30),70,30,$black,"resources/fonts/Duality.ttf",$fourth); // se puede cambiar varios modelo de fuente
// Para añadir más caracters a la imagen se debe multiplicar estos parametros al caracters deseado
/*
imagettftext($image,25,mt_rand(-40,30),70,30,$black,"resources/fonts/Duality.ttf",$fourth);
*/
header("content-type:image/png");
imagepng($image);
?>
based on this comment
To create an image using one
array
for colors, anotherarray
for fonts, and get a word from a file.txt
, you can do the following:captcha.php file
Words.txt file ( no blank lines )
index.php file
Results:
To make a Google -like image
I recommend that you read inquire about the bookstore
Imagen Magick
. This article can give you a couple of ideas.Here's one
snippet
as an example:Result:
J. Doe, have you tried using
imagefill()
and filling it with the assigned colorimagecolorallocatealpha()
which can have a value between 0 and127
, ie 0 indicates completely opaque while 127 indicates completely transparent.It could be something like this:
OS source code:
Handbook
imagecolorallocatealpha()
:Handbook
imagefill()
:if you use imagecolortransparent()?
Here I leave you an example: