Beispiel #1
0
// Felixkat - Removed width and height.  Now specified by font size.
// $width = $session->get('com_fabrik.element.captach.width', 100);
// $height = $session->get('com_fabrik.element.captach.height', 50);
$fontsize = $session->get('com_fabrik.element.captach.fontsize', 30);
$angle = $session->get('com_fabrik.element.captach.angle', 0);
$padding = $session->get('com_fabrik.element.captach.padding', 10);
$font = $session->get('com_fabrik.element.captach.font', 'monofont.ttf');
$b_color = $session->get('com_fabrik.element.captach.bg_color', '255+255+255');
$bc = explode('+', $b_color);
$n_color = $session->get('com_fabrik.element.captach.noise_color', '0+0+255');
$nc = explode('+', $n_color);
$t_color = $session->get('com_fabrik.element.captach.text_color', '0+0+255');
$tc = explode('+', $t_color);
/* create textbox and add text */
$fontPath = JPATH_SITE . '/plugins/fabrik_element/captcha/' . $font;
$the_box = calculateTextBox($code, $fontPath, $fontsize, $angle);
$imgWidth = $the_box["width"] + $padding;
$imgHeight = $the_box["height"] + $padding;
$image = imagecreate($imgWidth, $imgHeight) or die('Cannot initialize new GD image stream');
$background_color = imagecolorallocate($image, $bc[0], $bc[1], $bc[2]);
$text_color = imagecolorallocate($image, $tc[0], $tc[1], $tc[2]);
$noise_color = imagecolorallocate($image, $nc[0], $nc[1], $nc[2]);
/* generate random dots in background */
for ($i = 0; $i < $imgWidth * $imgHeight / 3; $i++) {
    imagefilledellipse($image, mt_rand(0, $imgWidth), mt_rand(0, $imgHeight), 1, 1, $noise_color);
}
/*  generate random lines in background */
for ($i = 0; $i < $imgWidth * $imgHeight / 150; $i++) {
    imageline($image, mt_rand(0, $imgWidth), mt_rand(0, $imgHeight), mt_rand(0, $imgWidth), mt_rand(0, $imgHeight), $noise_color);
}
imagettftext($image, $fontsize, $angle, $the_box["left"] + $imgWidth / 2 - $the_box["width"] / 2, $the_box["top"] + $imgHeight / 2 - $the_box["height"] / 2, $text_color, $fontPath, $code) or die('Error in imagettftext function');
    $bgcolorlevel = min(max((int) $_GET["bgcolor"], 0), 255);
}
//The textcolor 0 to 255
if (!isset($_GET["textcolor"])) {
    $textcolorlevel = 50;
} else {
    $textcolorlevel = min(max((int) $_GET["textcolor"], 0), 255);
}
//is the background color tranparent?
$transparent = isset($_GET["transparent"]) && !empty($_GET["transparent"]);
$font = dirname(__FILE__) . '/arial.ttf';
//Font file must be on the same folder
if (!file_exists($font)) {
    die("The font file does not exist.");
}
$box = calculateTextBox($text, $font, $size);
//Dinamically calculate the text box
$width = $box["width"] + $padding * 2;
$height = $box["height"] + $padding * 2;
$image = imagecreate($width, $height) or die("Cannot Initialize new GD image stream. Please Install the PHP-GD extension.");
$bgcolor = imagecolorallocate($image, $bgcolorlevel, $bgcolorlevel, $bgcolorlevel);
//Always gray scale
$textcolor = imagecolorallocate($image, $textcolorlevel, $textcolorlevel, $textcolorlevel);
//Always gray scale
imagefill($image, $width, $height, $bgcolor);
//Fill the background
if ($transparent) {
    imagecolortransparent($image, $bgcolor);
    //Set the bg color to transparent
}
//Write the text
Beispiel #3
0
$colorB = base_convert(substr($colorHtml, 4, 2), 16, 10);
$code = intval($_GET['code']);
$size = intval($_GET['size']);
if ($code < 0 || $code > 65535) {
    die('Incorrect `code` value');
}
if ($size < $config['minSize']) {
    $size = $config['minSize'];
}
if ($size > $config['maxSize']) {
    $size = $config['maxSize'];
}
$fontFile = dirname(__FILE__) . '/icons.ttf';
$text = html_entity_decode('&#' . $code . ';', ENT_COMPAT, 'UTF-8');
//$dim = imagettfbbox($size, 0,  $fontFile, $text);
$dim = calculateTextBox($size, 0, $fontFile, $text);
/*$dim = array(
    'width': $size,
    'height' : $size,
    'left' : 0,
    'top': 0
);*/
$width = $dim['width'];
$height = $dim['height'];
$left = $dim['left'];
$top = $dim['top'];
$img = @imagecreatetruecolor($width, $height) or die("Cannot Initialize new GD image stream. Check GD library in installed on server and selected font for existence.");
imagesavealpha($img, true);
$trans_colour = imagecolorallocatealpha($img, 0, 0, 0, 127);
imagefill($img, 0, 0, $trans_colour);
$color = imagecolorallocate($img, $colorR, $colorG, $colorB);
$root = "../../..";
if (file_exists($root.'/wp-load.php')) {
	require_once($root.'/wp-load.php');
} else {
	require_once($root.'/wp-config.php');
}

$options_table = $wpdb->prefix . "lici_options";
$comments = get_comments_number($cid);
$login = $wpdb->get_row("SELECT * FROM $options_table WHERE `id`='$lid' LIMIT 1;");

$color = $login->fontcolor;
$font = "./fonts/".$login->font;
$size = $login->fontsize;

$box = calculateTextBox($size, 0, $font, $comments);

//print_r($box); 

$im=imagecreatetruecolor($box['width'],$box['height']);
imagealphablending($im,false);
$col=imagecolorallocatealpha($im,255,255,255,127);
//$col=imagecolorallocate($im,255,255,255);
imagefilledrectangle($im,0,0,$box['width'],$box['height'],$col);
imagealphablending($im,true);

if ($im) {
	
	$co = RGB2Hex2RGB("#".$color);
	$color_a = imagecolorallocatealpha($im, $co['r'], $co['g'],$co['b'], 0);
	imagettftext($im, $size, 0, -1, $box['height'], $color_a, "fonts/vera.ttf", $comments);
Beispiel #5
0
       simple function that calculates the *exact* bounding box (single pixel precision).
       The function returns an associative array with these keys:
       left, top:  coordinates you will pass to imagettftext
       width, height: dimension of the image you have to create
       *************/
    $rect = imagettfbbox($fontSize, $fontAngle, $fontFile, $text);
    $minX = min(array($rect[0], $rect[2], $rect[4], $rect[6]));
    $maxX = max(array($rect[0], $rect[2], $rect[4], $rect[6]));
    $minY = min(array($rect[1], $rect[3], $rect[5], $rect[7]));
    $maxY = max(array($rect[1], $rect[3], $rect[5], $rect[7]));
    return array("left" => abs($minX) - 1, "top" => abs($minY) - 1, "width" => $maxX - $minX, "height" => $maxY - $minY, "box" => $rect);
}
// Example usage - gif image output
$text_string = "Hello World";
$font_ttf = "/var/www/html/samples/php/watermark/case2/fonts/arial.ttf";
$font_size = 22;
$text_angle = 0;
$text_padding = 10;
// Img padding - around text
$the_box = calculateTextBox($text_string, $font_ttf, $font_size, $text_angle);
$imgWidth = $the_box["width"] + $text_padding;
$imgHeight = $the_box["height"] + $text_padding;
$image = imagecreate($imgWidth, $imgHeight);
imagefill($image, imagecolorallocate($image, 200, 200, 200));
$color = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, $font_size, $text_angle, $the_box["left"] + $imgWidth / 2 - $the_box["width"] / 2, $the_box["top"] + $imgHeight / 2 - $the_box["height"] / 2, $color, $font_ttf, $text_string);
header("Content-Type: image/gif");
imagegif($image);
imagedestroy($image);
?>