Mit ein bisschen Raffinesse lassen sich die reCaptcha Bilder in eigene Bilder hineinkopieren - ohne den weißen Hintergrund.
Benötigt wird ein Webserver mit PHP und aktiver GD Erweiterung (Ist zu 99% immer aktiviert)
so könnte es zb aussehen:
Folgenden Code kopieren, die 2 Funktionen ggf in andere Dateien auslagern, Keys eintragen und Rest ebenfalls nach Wunsch anpassen
Weiß nich unter welchen Bedingungen ich dies veröffentlichen darf, daher gibs das ma als Example-SourceCode und nich in meiner WebLib =)
Benötigt wird ein Webserver mit PHP und aktiver GD Erweiterung (Ist zu 99% immer aktiviert)
so könnte es zb aussehen:
Folgenden Code kopieren, die 2 Funktionen ggf in andere Dateien auslagern, Keys eintragen und Rest ebenfalls nach Wunsch anpassen
PHP-Quellcode
- <?php
- ///////////////////////////////////////
- // additional recaptcha functions
- function recaptcha_load_challange($publicKey)
- {
- $recaptchaStateJS = @file_get_contents("http://www.google.com/recaptcha/api/challenge?k=$publicKey");
- if (!$recaptchaStateJS) die("recaptcha_load_challange: cannot load file");
- if (!preg_match("/challenge\s*?\:\s*?\'([^\']+)\'/", $recaptchaStateJS, $recaptchaChallange)) die("recaptcha_load_challange: cannot find field");
- return $recaptchaChallange[1];
- }
- function recaptcha_merge_images($challange, $targetImage, $targetStartX, $targetStartY)
- {
- if (!is_string($challange)) die("recaptcha_merge_images: challange is no string");
- if (!is_resource($targetImage)) die("recaptcha_merge_images: targetImage is no resource");
- if (!is_numeric($targetStartX)) die("recaptcha_merge_images: targetStartX is no number");
- if (!is_numeric($targetStartY)) die("recaptcha_merge_images: targetStartY is no number");
- $targetStartX = (int)round($targetStartX);
- $targetStartY = (int)round($targetStartY);
- $recaptchaImage = @file_get_contents("http://www.google.com/recaptcha/api/image?c=$challange");
- if (!$recaptchaImage) die("recaptcha_merge_images: cannot load image");
- $recaptchaImage = imagecreatefromstring($recaptchaImage);
- if (!$recaptchaImage) die("recaptcha_merge_images: cannot read image");
- $recaptchaWidth = imagesx($recaptchaImage);
- $recaptchaHeight = imagesy($recaptchaImage);
- $targetWidth = imagesx($targetImage);
- $targetHeight = imagesy($targetImage);
- $targetWidth = ($recaptchaWidth+$targetStartX >= $targetWidth) ? $targetWidth-$targetStartX : $recaptchaWidth;
- $targetHeight = ($recaptchaHeight+$targetStartY >= $targetHeight) ? $targetHeight-$targetStartY : $recaptchaHeight;
- $recaptchaStartX = ($targetStartX < 0) ? $targetStartX*-1 : 0;
- $recaptchaStartY = ($targetStartY < 0) ? $targetStartY*-1 : 0;
- if ($targetWidth <= 0 || $targetHeight <= 0) die("err 5");
- function rgba2int($r, $g, $b, $a=0)
- {
- return ($a << 24) + ($r << 16) + ($g << 8) + $b;
- }
- function int2rgba($int)
- {
- return array(
- 3 => ($int >> 24) & 0xFF,
- 0 => ($int >> 16) & 0xFF,
- 1 => ($int >> 8) & 0xFF,
- 2 => $int & 0xFF
- );
- $a = ($int >> 24) & 0xFF;
- $r = ($int >> 16) & 0xFF;
- $g = ($int >> 8) & 0xFF;
- $b = $int & 0xFF;
- return array($r, $g, $b, $a);
- }
- function distance($r, $g, $b)
- {
- return sqrt($r*$r + $g*$g + $b*$b);
- }
- $maxDistance = 441.6729559300637098;
- for ($x=$recaptchaStartX; $x<$targetWidth; $x++)
- for ($y=$recaptchaStartY; $y<$targetHeight; $y++)
- {
- $targetColor = int2rgba(imagecolorat($targetImage, $x+$targetStartX, $y+$targetStartY));
- $recaptchaColor = int2rgba(imagecolorat($recaptchaImage, $x, $y));
- $percent = 1 / $maxDistance * distance($recaptchaColor[0], $recaptchaColor[1], $recaptchaColor[2]);
- imagesetpixel(
- $targetImage,
- $x+$targetStartX,
- $y+$targetStartY,
- rgba2int(
- round(min(255, $recaptchaColor[0]*(1-$percent) + $targetColor[0]*$percent)),
- round(min(255, $recaptchaColor[1]*(1-$percent) + $targetColor[1]*$percent)),
- round(min(255, $recaptchaColor[2]*(1-$percent) + $targetColor[2]*$percent))
- )
- );
- }
- imagedestroy($recaptchaImage);
- return $targetImage;
- }
- ///////////////////////////////////////
- $recaptchaPublic = "oOoOo0o0ooOoooO0OoOOoOO0OO0o0oO0O0Ooo";
- $recaptchaPrivate = "li1II1II1IlIII1iIililli1i11ilIi1";
- if (isset($_GET["go"]))
- switch($_GET["go"])
- {
- case "image":
- if (!isset($_GET["challange"])) die("...");
- $image = recaptcha_merge_images(
- $_GET["challange"],
- imagecreatefrompng("preview.png"),
- 50, // start x
- 50 // start y
- );
- // keep alpha
- imagealphablending($image, true);
- imagesavealpha($image, true);
- // output
- header('Content-Type: image/png');
- imagepng($image);
- imagedestroy($image);
- // and exit
- exit();
- break;
- case "verify":
- if (!isset($_POST["challange"])) die("...");
- if (!isset($_POST["answer"])) die("...");
- require_once('recaptchalib.php');
- $resp = recaptcha_check_answer(
- $recaptchaPrivate,
- $_SERVER["REMOTE_ADDR"],
- $_POST["challange"],
- $_POST["answer"]
- );
- if (!$resp->is_valid) {
- die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
- "(reCAPTCHA said: " . $resp->error . ")");
- } else {
- echo "answer was correct";
- // Your code here to handle a successful verification
- }
- exit();
- break;
- }
- $challange = recaptcha_load_challange($recaptchaPublic);
- ?>
- <html>
- <body>
- <form method="post" action="?go=verify">
- <img src="?go=image&challange=<?php echo $challange; ?>">
- <input type="hidden" name="challange" value="<?php echo $challange; ?>" />
- <input type="text" name="answer" />
- <input type="submit" />
- </form>
- </body>
- </html>
Weiß nich unter welchen Bedingungen ich dies veröffentlichen darf, daher gibs das ma als Example-SourceCode und nich in meiner WebLib =)