function image_captcha_image in CAPTCHA 6.2
Same name and namespace in other branches
- 5.3 image_captcha/image_captcha.module \image_captcha_image()
- 6 image_captcha/image_captcha.user.inc \image_captcha_image()
- 7 image_captcha/image_captcha.user.inc \image_captcha_image()
Menu callback function that generates the CAPTCHA image.
1 string reference to 'image_captcha_image'
- image_captcha_menu in image_captcha/
image_captcha.module - Implementation of hook_menu().
File
- image_captcha/
image_captcha.user.inc, line 14 - Functions for the generation of the CAPTCHA image.
Code
function image_captcha_image($captcha_sid = NULL) {
// If output buffering is on: discard current content and disable further buffering
if (ob_get_level()) {
ob_end_clean();
}
if (!$captcha_sid) {
exit;
}
// Get solution (the code to show).
$code = db_result(db_query("SELECT solution FROM {captcha_sessions} WHERE csid = %d", (int) $captcha_sid));
// Only generate captcha if code exists in the session.
if ($code !== FALSE) {
// generate the image
$image = @_image_captcha_generate_image($code);
// check of generation was successful
if (!$image) {
watchdog('CAPTCHA', 'Generation of image CAPTCHA failed. Check your image CAPTCHA configuration and especially the used font.', array(), WATCHDOG_ERROR);
exit;
}
// Send the image resource as an image file to the client.
$file_format = variable_get('image_captcha_file_format', IMAGE_CAPTCHA_FILE_FORMAT_JPG);
if ($file_format == IMAGE_CAPTCHA_FILE_FORMAT_JPG) {
drupal_set_header("Content-type: image/jpeg");
imagejpeg($image);
}
else {
drupal_set_header("Content-type: image/png");
imagepng($image);
}
// Clean up the image resource.
imagedestroy($image);
}
exit;
}