GD library letters vervormen
Ik wil graag letters kunnen vervormen met GD library van php. Net zoals veel captcha afbeeldingen dat hebben. Het is echter niet omdat ik het wil gebruiken voor een captcha.
Ik vind op internet alleen manieren om de letters te draaien etc. Maar niet echt om ze te verkreukelen enzo.
Hoe kan ik dit doen?
Ik vind op internet alleen manieren om de letters te draaien etc. Maar niet echt om ze te verkreukelen enzo.
Hoe kan ik dit doen?
Je moet de pixel coordinaten vervormen met een wiskundige functie. Dit zou je zo kunnen doen:
Resulaat van onderstaande code: http://i.imgur.com/3cUxR2V.png
Het is leuk om mee te spelen als je van wiskunde houdt. Als dit niet het geval is, pak dan een kant-en-klare captcha library.
Resulaat van onderstaande code: http://i.imgur.com/3cUxR2V.png
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$input = "Warped text!";
$width = 200;
$height = 200;
// Allocate initial image with a solid white background.
$original = imagecreatetruecolor($width, $height);
imagefill($original, 0, 0, imagecolorallocate($original, 255, 255, 255));
// Write something onto the original image:
imagestring($original, 5, 0, 0, $input, imagecolorallocate($original, 0, 0, 0));
// A target image, we'll warp the original and render onto this canvas.
$warped = imagecreatetruecolor($width, $height);
imagefill($warped, 0, 0, imagecolorallocate($warped, 255, 255, 255));
// Iteratore over each pixel and warp the coordinates
for($x = 0; $x < $width; ++$x) {
for($y = 0; $y < $height; ++$y) {
// Sample color of the original image
$components = imagecolorsforindex($original, imagecolorat($original, $x, $y));
// Create a new color for the warped image
$color = imagecolorallocate($warped, $components["red"], $components["green"], $components["blue"]);
// Warp the target X / Y coordinates
$warpX = $x;
$warpY = $y + sin($x / 30) * 10;
imagesetpixel($warped, $warpX, $warpY, $color);
}
}
// Output the image
header('Content-type: image/png');
imagepng($warped);
// Destroy allocated resources
imagedestroy($warped);
imagedestroy($original);
?>
$input = "Warped text!";
$width = 200;
$height = 200;
// Allocate initial image with a solid white background.
$original = imagecreatetruecolor($width, $height);
imagefill($original, 0, 0, imagecolorallocate($original, 255, 255, 255));
// Write something onto the original image:
imagestring($original, 5, 0, 0, $input, imagecolorallocate($original, 0, 0, 0));
// A target image, we'll warp the original and render onto this canvas.
$warped = imagecreatetruecolor($width, $height);
imagefill($warped, 0, 0, imagecolorallocate($warped, 255, 255, 255));
// Iteratore over each pixel and warp the coordinates
for($x = 0; $x < $width; ++$x) {
for($y = 0; $y < $height; ++$y) {
// Sample color of the original image
$components = imagecolorsforindex($original, imagecolorat($original, $x, $y));
// Create a new color for the warped image
$color = imagecolorallocate($warped, $components["red"], $components["green"], $components["blue"]);
// Warp the target X / Y coordinates
$warpX = $x;
$warpY = $y + sin($x / 30) * 10;
imagesetpixel($warped, $warpX, $warpY, $color);
}
}
// Output the image
header('Content-type: image/png');
imagepng($warped);
// Destroy allocated resources
imagedestroy($warped);
imagedestroy($original);
?>
Het is leuk om mee te spelen als je van wiskunde houdt. Als dit niet het geval is, pak dan een kant-en-klare captcha library.




