Example #1
1
function text2etc($text, $CP, $mode = "png", $trans = 1)
{
    global $TTF_LOCATION, $FONT_SIZE;
    //$outputtext = implode('',file($f));
    $outputtext = $text;
    $outputtext = Conv2UTF8($outputtext, 1, $CP);
    $outputtext = str_replace("\r\n", "\n", $outputtext);
    $outputtext = str_replace("\r", "\n", $outputtext);
    $outputtext = str_replace("\n", "\r\n", $outputtext);
    $outputtext = str_replace("<br />", "\r\n", $outputtext);
    $outputtext = str_replace("&nbsp;", " ", $outputtext);
    $outputtext = unhtmlentities($outputtext);
    if ($mode == "png") {
        $dim = imageftbbox($FONT_SIZE, 0, $TTF_LOCATION, $outputtext, array("linespacing" => 1.0));
        #		$dim= imagettfbbox($FONT_SIZE, 0, $TTF_LOCATION, $outputtext);
        $min_x = min($dim[0], $dim[2], $dim[4], $dim[6]);
        $max_x = max($dim[0], $dim[2], $dim[4], $dim[6]);
        $width = $max_x - $min_x + 1;
        $min_y = min($dim[1], $dim[3], $dim[5], $dim[7]);
        $max_y = max($dim[1], $dim[3], $dim[5], $dim[7]);
        $height = $max_y - $min_y + 1;
        $img = imagecreate($width + 1, $height + 1);
        $white = ImageColorAllocate($img, 255, 255, 255);
        if ($trans) {
            $twhite = imagecolortransparent($img, $white);
        }
        $black = ImageColorAllocate($img, 0, 0, 0);
        #		ImageTTFText($img, $FONT_SIZE, 0, -$min_x+$dim[0],-$min_y, $black, $TTF_LOCATION, $outputtext);
        ImageFTText($img, $FONT_SIZE, 0, -$min_x + $dim[0], -$min_y, $black, $TTF_LOCATION, $outputtext, array("linespacing" => 1.0));
        Header("Content-type: image/png");
        ImagePng($img);
        ImageDestroy($img);
    } else {
        if ($mode == "pre") {
            echo "<pre>\n{$outputtext}\n</pre>";
        } else {
            if ($mode == "text") {
                Header("Content-type: text/plain");
                echo utf8Encode($outputtext);
            }
        }
    }
}
Example #2
0
/**
 *
 * @copyright  2010-2012 izend.org
 * @version    2
 * @link       http://www.izend.org
 */
function strtag($text)
{
    $len = strlen($text);
    $fontfile = ROOT_DIR . DIRECTORY_SEPARATOR . 'font.ttf';
    $fontsize = 24.0;
    $bbox = imageftbbox($fontsize, 0, $fontfile, $text);
    $w = $bbox[2] + $len * 15;
    $h = 40;
    $img = @imagecreatetruecolor($w, $h) or die;
    $bg = imagecolorallocate($img, 255, 255, 224);
    $fg = imagecolorallocate($img, 64, 64, 64);
    imagefill($img, 0, 0, $bg);
    // print text unevenly
    for ($x = 15, $i = 0; $i < $len; $i++) {
        $y = rand($h / 2, $h / 2 + 15);
        $r = rand(-45, 45);
        imagettftext($img, $fontsize, $r, $x, $y, $fg, $fontfile, $text[$i]);
        $x += rand(25, 35);
    }
    // blur with colored dots
    for ($i = 0; $i < $w * $h / 2.0; $i++) {
        $color = imagecolorallocate($img, rand(128, 255), rand(128, 255), rand(128, 255));
        imagesetpixel($img, rand(0, $w - 1), rand(0, $h - 1), $color);
    }
    return $img;
}
Example #3
0
 /**
  *
  * @param <type> $string
  * @param <type> $cl
  * @param <type> $size
  * @return img
  */
 public function CenteredText($string, $size = 10)
 {
     $axes = imageftbbox($size, 0, $this->font, $string);
     $x = $this->w / 2 - ($axes[2] - $axes[0]) / 2;
     $y = $this->h / 2 - ($axes[7] - $axes[1]) / 2;
     imagefttext($this->im, $size, 0, $x, $y, $this->color, $this->font, $string);
     return $this;
 }
Example #4
0
/**
 * Determines the height and width of a specified string on screen
 *
 * @param $font		String	Name of font (with file extension) used
 * @param $text		String	Text of which the size should be determined
 * @param $angle	String	Angle for showing the text
 * @param $size		Int		Text size for printing the text
 * @return			Array	Array with two elements: first element is the width of the textbox, second is the height
 */
function wfPChart4mwtextboxSize($font, $text, $angle = 0, $size = 0)
{
    global $wgPChart4mwFontPath;
    // Determine the bounding box using the GD library
    $bbox = imageftbbox($size, $angle, $wgPChart4mwFontPath . "/" . $font, $text);
    // Compute the size
    return array(max($bbox[0], $bbox[2], $bbox[4], $bbox[6]) - min($bbox[0], $bbox[2], $bbox[4], $bbox[6]), max($bbox[1], $bbox[3], $bbox[5], $bbox[7]) - min($bbox[1], $bbox[3], $bbox[5], $bbox[7]));
}
 /**
  * (non-PHPdoc)
  * @see Imagine\Image\FontInterface::box()
  */
 public function box($string, $angle = 0)
 {
     $angle = -1 * $angle;
     $info = imageftbbox($this->size, $angle, $this->file, $string);
     $xs = array($info[0], $info[2], $info[4], $info[6]);
     $ys = array($info[1], $info[3], $info[5], $info[7]);
     $width = abs(max($xs) - min($xs));
     $height = abs(max($ys) - min($ys));
     return new Box($width, $height);
 }
/**
 * Determines an appropriate height for the legend
 *
 * @param  $dataset   Our dataset containing the values we need to check for sizes
 * @param  $font      A reference to the font file used
 * @param  $fontsize  The fontsize used
 *
 * @return            The vertical height of the text, plus a small margin
 */
function get_legend_height($dataset, $font, $fontsize)
{
    $description = $dataset->GetDataDescription();
    $total_value = 0;
    foreach ($description["Description"] as $key => $value) {
        $position = imageftbbox($fontsize, 0, $font, $value);
        $textheight = $position[1] - $position[7];
        $total_value += abs($textheight);
    }
    return $total_value + 20;
}
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function box($string, $angle = 0)
 {
     if (!function_exists('imageftbbox')) {
         throw new RuntimeException('GD must have been compiled with `--with-freetype-dir` option to use the Font feature.');
     }
     $angle = -1 * $angle;
     $info = imageftbbox($this->size, $angle, $this->file, $string);
     $xs = array($info[0], $info[2], $info[4], $info[6]);
     $ys = array($info[1], $info[3], $info[5], $info[7]);
     $width = abs(max($xs) - min($xs));
     $height = abs(max($ys) - min($ys));
     return new Box($width, $height);
 }
Example #8
0
 /**
  * Calculate text bbox using size, angle, font and value
  *
  * {@inheritdoc}
  */
 function getBbox()
 {
     $bbox = imageftbbox($this->size, $this->angle, $this->font, $this->value);
     $boxWidth = $bbox[4] - $bbox[0];
     $boxHeight = $bbox[1] - $bbox[5];
     $boxX = 0;
     $boxY = 0;
     $lines = explode("\n", $this->value);
     if (count($lines) > 1) {
         $boxY = -($bbox[1] / count($lines));
     }
     return array($boxX, $boxY, $boxWidth, $boxHeight);
 }
Example #9
0
 /**
  * Description: a creation of a cookie
  * Example:     $config = [
  *       			'path'       => 'files/images/captcha',
  *       			'text'       => 'Some text...',
  *       			'expiration' => 60,
  *       			'font'       => 'app/fonts/simple.ttf',
  *       			'angle'      => 0,
  *       			'width'      => 300,
  *       			'height'     => 50,
  *              	'fontSize'   => 18,
  *       			'colors'     => [
  *                  	'text'       => [255, 200, 168],
  *           			'background' => [255, 255, 255]
  *       			]
  *              ];
  *              Captcha::create($config);
  * @param       array|$config
  * @return      array
  *				(
  *				    [path]     => files/images/captcha/1438642230.5518.png
  *				    [fullPath] => C:/OpenServer/domains/localhost/framework/files/images/captcha/1438642230.5518.png
  *				    [name]     => 1438642230.5518.png
  *				)
  */
 public static function create(array $config)
 {
     $colors = ['text' => [0, 0, 0], 'background' => [255, 255, 255]];
     $param = ['path' => 'files/images/captcha', 'text' => 'Some text', 'expiration' => '3600', 'font' => VENDIR . 'simple/fonts/simple.ttf', 'angle' => 0, 'width' => 300, 'height' => 50, 'fontSize' => 16, 'colors' => $colors];
     //set the config
     foreach ($config as $key => $value) {
         $param[$key] = $config[$key];
     }
     //set the colors
     foreach ($param['colors'] as $key => $value) {
         $colors[$key] = $config['colors'][$key];
     }
     //set the colors array
     $colors = $config['colors'];
     //the removal of the old captcha images
     $now = microtime(true);
     if (file_exists('files/images/captcha/')) {
         foreach (glob('files/images/captcha/*') as $file) {
             $fileName = explode('.', basename($file));
             $fileName = (int) $fileName[0];
             if ($fileName + $param['expiration'] < $now) {
                 unlink($file);
             }
         }
     }
     //set the captcha name
     $captchaName = $now . '.png';
     //set the image path
     $imgPath = ROOT . $config['path'];
     $fullImgPath = str_replace(DIRECTORY_SEPARATOR, '/', $imgPath) . '/';
     $fullImgPath = str_replace('//', '/', $fullImgPath);
     $localPath = $config['path'] . '/';
     $localPath = str_replace('//', '/', $localPath);
     $imgTrueColor = imagecreatetruecolor($config['width'], $config['height']);
     //set the text color
     $textColor = imagecolorallocate($imgTrueColor, $colors['text'][0], $colors['text'][1], $colors['text'][2]);
     //set the background color
     $backgroundColor = imagecolorallocate($imgTrueColor, $colors['background'][0], $colors['background'][1], $colors['background'][2]);
     imagefilledrectangle($imgTrueColor, 0, 0, $param['width'], $param['height'], $backgroundColor);
     //set the font path
     $fontPath = str_replace(DIRECTORY_SEPARATOR, '/', ROOT . $config['font']);
     //create a text
     $bbox = imageftbbox(18, 0, $param['font'], $param['text']);
     $x = (imagesx($imgTrueColor) - $bbox[4]) / 2;
     $y = (imagesy($imgTrueColor) - $bbox[5]) / 2;
     imagettftext($imgTrueColor, $param['fontSize'], $param['angle'], $x, $y, $textColor, $fontPath, $param['text']);
     //create a png image
     imagepng($imgTrueColor, $fullImgPath . $captchaName);
     $result = ['path' => $localPath . $captchaName, 'fullPath' => $fullImgPath . $captchaName, 'name' => $captchaName];
     return $result;
 }
Example #10
0
 public function apply($resource)
 {
     // Find original dimensions:
     $imageWidth = imagesx($resource->image);
     $imageHeight = imagesy($resource->image);
     $fontbox = imageftbbox($this->settings->size, 0, realpath($this->settings->font), $this->settings->text);
     $width = $fontbox[4] - $fontbox[6];
     $width += $this->settings->padding * 2;
     $height = $fontbox[1] - $fontbox[7];
     $height += $this->settings->padding * 2;
     $image = imagecreatetruecolor($width, $height);
     $bg = new Colour($this->settings->bg);
     $fg = new Colour($this->settings->fg);
     $bg = $bg->allocate($image);
     $fg = $fg->allocate($image);
     imagesavealpha($image, true);
     imagesavealpha($resource->image, true);
     imagefill($image, 0, 0, $bg);
     imagefttext($image, $this->settings->size, 0, $this->settings->padding, $this->settings->size + $this->settings->padding, $fg, realpath($this->settings->font), $this->settings->text);
     $margin = $this->settings->margin;
     // Calculate X alignment:
     if ($this->settings->xalign == 'left') {
         $offsetX = $margin;
     } else {
         if ($this->settings->xalign == 'right') {
             $offsetX = round(max($imageWidth, $width) - min($imageWidth, $width)) - $margin;
         } else {
             $offsetX = 0 - round((min($imageWidth, $width) - max($imageWidth, $width)) / 2);
         }
     }
     // Invert X:
     //if ($imageWidth < $width) {
     //	$offsetX = 0 - $offsetX;
     //}
     // Calculate Y alignment:
     if ($this->settings->yalign == 'top') {
         $offsetY = $margin;
     } else {
         if ($this->settings->yalign == 'bottom') {
             $offsetY = round(max($imageHeight, $height) - min($imageHeight, $height)) - $margin;
         } else {
             $offsetY = 0 - round((min($imageHeight, $height) - max($imageHeight, $height)) / 2);
         }
     }
     // Invert Y:
     //if ($imageHeight < $height) {
     //	$offsetY = 0 - $offsetY;
     //}
     imagecopyresampled($resource->image, $image, $offsetX, $offsetY, 0, 0, $width, $height, $width, $height);
 }
Example #11
0
 /**
  * Writes text onto an image.
  *
  * @param WideImage_Image $image
  * @param mixed           $x     smart coordinate
  * @param mixed           $y     smart coordinate
  * @param string          $text
  * @param int             $angle Angle in degrees clockwise
  */
 public function writeText($image, $x, $y, $text, $angle = 0)
 {
     if ($image->isTrueColor()) {
         $image->alphaBlending(true);
     }
     $box = imageftbbox($this->size, $angle, $this->face, $text);
     $obox = ['left' => min($box[0], $box[2], $box[4], $box[6]), 'top' => min($box[1], $box[3], $box[5], $box[7]), 'right' => max($box[0], $box[2], $box[4], $box[6]) - 1, 'bottom' => max($box[1], $box[3], $box[5], $box[7]) - 1];
     $obox['width'] = abs($obox['left']) + abs($obox['right']);
     $obox['height'] = abs($obox['top']) + abs($obox['bottom']);
     $x = WideImage_Coordinate::fix($x, $image->getWidth(), $obox['width']);
     $y = WideImage_Coordinate::fix($y, $image->getHeight(), $obox['height']);
     $fixed_x = $x - $obox['left'];
     $fixed_y = $y - $obox['top'];
     imagettftext($image->getHandle(), $this->size, $angle, $fixed_x, $fixed_y, $this->color, $this->face, $text);
 }
Example #12
0
 protected function setResource()
 {
     $ftbbox = imageftbbox($this->fontsize, 0, $this->fontfile, $this->text, array('linespacing' => $this->linespacing));
     $bugfix = ceil($this->fontsize / 5);
     $ftboxwidth = abs($ftbbox[0] - $ftbbox[2]) + $bugfix;
     $ftboxheight = abs($ftbbox[1] - $ftbbox[7]);
     $blockwidth = $ftboxwidth + $this->blockpadding[1] + $this->blockpadding[3];
     $blockheight = $ftboxheight + $this->blockpadding[0] + $this->blockpadding[2];
     $texttempx = $this->blockpadding[3];
     $texttempy = $this->blockpadding[0] - $ftbbox[7] - 1;
     $anglerad = deg2rad($this->angle);
     $textradius = sqrt(pow(abs($texttempx - $blockwidth / 2), 2) + pow(abs($texttempy - $blockheight / 2), 2));
     $blockradius = sqrt(pow($blockwidth, 2) + pow($blockheight, 2)) / 2;
     $blockx[0] = cos(atan2($blockheight / 2, -$blockwidth / 2) - $anglerad) * $blockradius + $blockwidth / 2;
     $blockx[1] = cos(atan2($blockheight / 2, $blockwidth / 2) - $anglerad) * $blockradius + $blockwidth / 2;
     $blockx[2] = cos(atan2(-$blockheight / 2, $blockwidth / 2) - $anglerad) * $blockradius + $blockwidth / 2;
     $blockx[3] = cos(atan2(-$blockheight / 2, -$blockwidth / 2) - $anglerad) * $blockradius + $blockwidth / 2;
     $blocky[0] = sin(atan2($blockheight / 2, -$blockwidth / 2) - $anglerad) * $blockradius + $blockheight / 2;
     $blocky[1] = sin(atan2($blockheight / 2, $blockwidth / 2) - $anglerad) * $blockradius + $blockheight / 2;
     $blocky[2] = sin(atan2(-$blockheight / 2, $blockwidth / 2) - $anglerad) * $blockradius + $blockheight / 2;
     $blocky[3] = sin(atan2(-$blockheight / 2, -$blockwidth / 2) - $anglerad) * $blockradius + $blockheight / 2;
     $minblockx = min($blockx[0], $blockx[1], $blockx[2], $blockx[3]);
     $minblocky = min($blocky[0], $blocky[1], $blocky[2], $blocky[3]);
     $blockx[0] = (int) round($blockx[0] - $minblockx);
     $blockx[1] = (int) round($blockx[1] - $minblockx);
     $blockx[2] = (int) round($blockx[2] - $minblockx);
     $blockx[3] = (int) round($blockx[3] - $minblockx);
     $blocky[0] = (int) round($blocky[0] - $minblocky);
     $blocky[1] = (int) round($blocky[1] - $minblocky);
     $blocky[2] = (int) round($blocky[2] - $minblocky);
     $blocky[3] = (int) round($blocky[3] - $minblocky);
     $textx = (int) round(cos(atan2($texttempy - $blockheight / 2, $texttempx - $blockwidth / 2) - $anglerad) * $textradius + $blockwidth / 2 - $minblockx);
     $texty = (int) round(sin(atan2($texttempy - $blockheight / 2, $texttempx - $blockwidth / 2) - $anglerad) * $textradius + $blockheight / 2 - $minblocky);
     $this->width = max(abs($blockx[0] - $blockx[2]), abs($blockx[1] - $blockx[3]));
     $this->height = max(abs($blocky[0] - $blocky[2]), abs($blocky[1] - $blocky[3]));
     $this->resource = imagecreatetruecolor($this->width, $this->height);
     $transparentcolor = imagecolorallocatealpha($this->resource, 255, 255, 255, 127);
     imagefill($this->resource, 0, 0, $transparentcolor);
     if (isset($this->blockcolor) === true) {
         $blockcolor = imagecolorallocate($this->resource, $this->blockcolor['red'], $this->blockcolor['green'], $this->blockcolor['blue']);
         if (function_exists('imageantialias')) {
             imageantialias($this->resource, true);
         }
         imagefilledpolygon($this->resource, array($blockx[0], $blocky[0], $blockx[1], $blocky[1], $blockx[2], $blocky[2], $blockx[3], $blocky[3]), 4, $blockcolor);
     }
     $fontcolor = imagecolorallocate($this->resource, $this->fontcolor['red'], $this->fontcolor['green'], $this->fontcolor['blue']);
     imagefttext($this->resource, $this->fontsize, $this->angle, $textx, $texty, $fontcolor, $this->fontfile, $this->text, array('linespacing' => $this->linespacing));
 }
Example #13
0
 /**
  * Outputs the Captcha image.
  *
  * @param   boolean  html output
  * @return  mixed
  */
 public function render()
 {
     // Init Challenge;
     $this->initChallenge();
     // Creates $this->image
     $this->createImage(Captcha::$config['background']);
     // Add a random gradient
     if (empty(Captcha::$config['background'])) {
         $color1 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         $color2 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         $this->gradientImage($color1, $color2);
     }
     // Add a few random circles
     for ($i = 0, $count = mt_rand(10, Captcha::$config['complexity'] * 3); $i < $count; $i++) {
         $color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255), mt_rand(80, 120));
         $size = mt_rand(5, Captcha::$config['height'] / 3);
         imagefilledellipse($this->image, mt_rand(0, Captcha::$config['width']), mt_rand(0, Captcha::$config['height']), $size, $size, $color);
     }
     // Calculate character font-size and spacing
     $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / strlen($this->response);
     $spacing = (int) (Captcha::$config['width'] * 0.9 / strlen($this->response));
     // Background alphabetic character attributes
     $color_limit = mt_rand(96, 160);
     $chars = 'ABEFGJKLPQRTVY';
     // Draw each Captcha character with varying attributes
     for ($i = 0, $strlen = strlen($this->response); $i < $strlen; $i++) {
         // Use different fonts if available
         $font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
         $angle = mt_rand(-40, 20);
         // Scale the character size on image height
         $size = $default_size / 10 * mt_rand(8, 12);
         $box = imageftbbox($size, $angle, $font, $this->response[$i]);
         // Calculate character starting coordinates
         $x = $spacing / 4 + $i * $spacing;
         $y = Captcha::$config['height'] / 2 + ($box[2] - $box[5]) / 4;
         // Draw captcha text character
         // Allocate random color, size and rotation attributes to text
         $color = imagecolorallocate($this->image, mt_rand(150, 255), mt_rand(200, 255), mt_rand(0, 255));
         // Write text character to image
         imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response[$i]);
         // Draw "ghost" alphabetic character
         $text_color = imagecolorallocatealpha($this->image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand(70, 120));
         $char = substr($chars, mt_rand(0, 14), 1);
         imagettftext($this->image, $size * 2, mt_rand(-45, 45), $x - mt_rand(5, 10), $y + mt_rand(5, 10), $text_color, $font, $char);
     }
     // Output
     return $this->renderImage();
 }
Example #14
0
/**
 *
 * @copyright  2010-2011 izend.org
 * @version    1
 * @link       http://www.izend.org
 */
function strlogo($name)
{
    $waspfile = ROOT_DIR . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'wasp.png';
    $fontfile = ROOT_DIR . DIRECTORY_SEPARATOR . 'font.ttf';
    $fontsize = 24.0;
    $bbox = imageftbbox($fontsize, 0, $fontfile, $name);
    $w = $bbox[2] + 48 + 5;
    $h = 40;
    $wasp = @imagecreatefrompng($waspfile) or die;
    $img = @imagecreatetruecolor($w, $h) or die;
    $bg = imagecolorallocate($img, 255, 255, 255);
    $fg = imagecolorallocate($img, 0x33, 0x33, 0x33);
    imagecolortransparent($img, $bg);
    imagefill($img, 0, 0, $bg);
    imagettftext($img, $fontsize, 0, 0, 30, $fg, $fontfile, $name);
    imagecopy($img, $wasp, $w - 48, 0, 0, 0, 48, 48);
    return $img;
}
Example #15
0
 function setAnnotation($Data, $DataDescription, $SerieName, $ValueName, $Caption, $R = 210, $G = 210, $B = 210)
 {
     /* Validate the Data and DataDescription array */
     $this->validateDataDescription("setLabel", $DataDescription);
     $this->validateData("setLabel", $Data);
     $ShadowFactor = 100;
     $C_Label = $this->AllocateColor($this->Picture, $R, $G, $B);
     $C_Shadow = $this->AllocateColor($this->Picture, $R - $ShadowFactor, $G - $ShadowFactor, $B - $ShadowFactor);
     $C_TextColor = $this->AllocateColor($this->Picture, 0, 0, 0);
     $Cp = 0;
     $Found = FALSE;
     foreach ($Data as $Key => $Value) {
         if ($Data[$Key][$DataDescription["Position"]] == $ValueName) {
             $NumericalValue = $Data[$Key][$SerieName];
             $Found = TRUE;
         }
         if (!$Found) {
             $Cp++;
         }
     }
     $XPos = $this->GArea_X1 + $this->GAreaXOffset + $this->DivisionWidth * $Cp + 2;
     $YPos = $this->GArea_Y2 - ($NumericalValue - $this->VMin) * $this->DivisionRatio;
     $Position = imageftbbox($this->FontSize, 0, $this->FontName, $Caption);
     $TextHeight = $Position[3] - $Position[5];
     $TextWidth = $Position[2] - $Position[0] + 2;
     $TextOffset = floor($TextHeight / 2);
     // Shadow
     /*
          $Poly = array($XPos+1,$YPos+1,$XPos + 9,$YPos - $TextOffset,$XPos + 8,$YPos + $TextOffset + 2);
          imagefilledpolygon($this->Picture,$Poly,3,$C_Shadow);
          $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos - $TextOffset - .2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
          $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
          $this->drawFilledRectangle($XPos + 9,$YPos - $TextOffset-.2,$XPos + 13 + $TextWidth,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
     
          // Label background
          $Poly = array($XPos,$YPos,$XPos + 8,$YPos - $TextOffset - 1,$XPos + 8,$YPos + $TextOffset + 1);
          imagefilledpolygon($this->Picture,$Poly,3,$C_Label);
          $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos - $TextOffset - 1.2,$R,$G,$B);
          $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos + $TextOffset + 1.2,$R,$G,$B);
          $this->drawFilledRectangle($XPos + 8,$YPos - $TextOffset - 1.2,$XPos + 12 + $TextWidth,$YPos + $TextOffset + 1.2,$R,$G,$B);
     */
     $this->drawLine($XPos - 2, $YPos, $XPos - 2, $YPos - 50, 200, 200, 200);
     imagettftext($this->Picture, $this->FontSize, 90, $XPos, $YPos - 50, $C_TextColor, $this->FontName, $Caption);
 }
Example #16
0
 /**
  * Outputs the Captcha image.
  *
  * @param   boolean  html output
  * @return  mixed
  */
 public function render()
 {
     // Init Challenge;
     $this->initChallenge();
     // Creates $this->image
     $this->createImage(Captcha::$config['background']);
     // Add a random gradient
     if (empty(Captcha::$config['background'])) {
         $color1 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
         $color2 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
         $this->gradientImage($color1, $color2);
     }
     // Add a few random lines
     for ($i = 0, $count = mt_rand(5, Captcha::$config['complexity'] * 4); $i < $count; $i++) {
         $color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(100, 255), mt_rand(50, 120));
         imageline($this->image, mt_rand(0, Captcha::$config['width']), 0, mt_rand(0, Captcha::$config['width']), Captcha::$config['height'], $color);
     }
     // Calculate character font-size and spacing
     $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / (strlen($this->response) + 1);
     $spacing = (int) (Captcha::$config['width'] * 0.9 / strlen($this->response));
     // Draw each Captcha character with varying attributes
     for ($i = 0, $strlen = strlen($this->response); $i < $strlen; $i++) {
         // Use different fonts if available
         $font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
         // Allocate random color, size and rotation attributes to text
         $color = imagecolorallocate($this->image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150));
         $angle = mt_rand(-40, 20);
         // Scale the character size on image height
         $size = $default_size / 10 * mt_rand(8, 12);
         $box = imageftbbox($size, $angle, $font, $this->response[$i]);
         // Calculate character starting coordinates
         $x = $spacing / 4 + $i * $spacing;
         $y = Captcha::$config['height'] / 2 + ($box[2] - $box[5]) / 4;
         // Write text character to image
         imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response[$i]);
     }
     // Output
     return $this->renderImage();
 }
Example #17
0
 public function render()
 {
     if (empty($this->response)) {
         $this->creat_code();
     }
     $this->image_create($this->config['background']);
     if (empty($this->config['background'])) {
         $color1 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         $color2 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         $this->image_gradient($color1, $color2);
     }
     for ($i = 0, $count = mt_rand(10, $this->config['complexity'] * 3); $i < $count; $i++) {
         $color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255), mt_rand(80, 120));
         $size = mt_rand(5, $this->config['height'] / 3);
         imagefilledellipse($this->image, mt_rand(0, $this->config['width']), mt_rand(0, $this->config['height']), $size, $size, $color);
     }
     $default_size = min($this->config['width'], $this->config['height'] * 2) / strlen($this->response);
     $spacing = (int) ($this->config['width'] * 0.9 / strlen($this->response));
     $color_limit = mt_rand(96, 160);
     $chars = 'ABEFGJKLPQRTVY';
     for ($i = 0, $strlen = strlen($this->response); $i < $strlen; $i++) {
         $font = FW_PATH . 'resource' . DIRECTORY_SEPARATOR . 'font' . DIRECTORY_SEPARATOR . $this->config['fonts'][array_rand($this->config['fonts'])];
         $angle = mt_rand(-40, 20);
         $size = $default_size / 10 * mt_rand(8, 12);
         if (!function_exists('imageftbbox')) {
             throw new Exception('function imageftbbox not exist.');
         }
         $box = imageftbbox($size, $angle, $font, $this->response[$i]);
         $x = $spacing / 4 + $i * $spacing;
         $y = $this->config['height'] / 2 + ($box[2] - $box[5]) / 4;
         $color = imagecolorallocate($this->image, mt_rand(150, 255), mt_rand(200, 255), mt_rand(0, 255));
         imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response[$i]);
         $text_color = imagecolorallocatealpha($this->image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand(70, 120));
         $char = substr($chars, mt_rand(0, 14), 1);
         imagettftext($this->image, $size * 1.4, mt_rand(-45, 45), $x - mt_rand(5, 10), $y + mt_rand(5, 10), $text_color, $font, $char);
     }
     return $this->image_render();
 }
 /**
  * Add text to an image, wrapping based on number of characters.
  */
 private function addWrappedTextToImage($imageHandle, $font, $text, $fontSize, $lineSpacing, $startY, $color)
 {
     //Get the total string length
     $textBox = imageftbbox($fontSize, 0, $font, $text);
     $totalTextWidth = abs($textBox[4] - $textBox[6]);
     //Determine how many lines we will need to break the text into
     $numLines = (double) $totalTextWidth / (double) $this->imagePrintableAreaWidth;
     $charactersPerLine = strlen($text) / $numLines;
     //Wrap based on the number of lines
     $lines = explode("\n", wordwrap($text, $charactersPerLine, "\n"));
     foreach ($lines as $line) {
         //Get the width of this line
         $lineBox = imageftbbox($fontSize, 0, $font, $line);
         $lineWidth = abs($lineBox[4] - $lineBox[6]);
         $lineHeight = abs($lineBox[3] - $lineBox[5]);
         //Get the starting position for the text
         $x = ($this->imageWidth - $lineWidth) / 2;
         $startY += $lineHeight;
         //Write the text to the image
         imagefttext($imageHandle, $fontSize, 0, $x, $startY, $color, $font, $line);
         $startY += $lineSpacing;
     }
     return $startY;
 }
Example #19
0
 public function draw($text)
 {
     $this->lineHeight = $this->lineHeight * $this->fontSize;
     $this->leading = $this->leading * $this->lineHeight - $this->lineHeight;
     $lines = array();
     // Split text explicitly into lines by \n, \r\n and \r
     $explicitLines = preg_split('/\\n|\\r\\n?/', $text);
     foreach ($explicitLines as $line) {
         // Check every line if it needs to be wrapped
         $words = explode(" ", $line);
         $line = $words[0];
         for ($i = 1; $i < count($words); $i++) {
             $box = imageftbbox($this->fontSize, 0, $this->fontFace, $line . " " . $words[$i]);
             if ($box[4] - $box[6] >= $this->box['width']) {
                 $lines[] = $line;
                 $line = $words[$i];
             } else {
                 $line .= " " . $words[$i];
             }
         }
         $lines[] = $line;
     }
     if ($this->debug == true) {
         imagefilledrectangle($this->im, $this->box['x'], $this->box['y'], $this->box['x'] + $this->box['width'], $this->box['y'] + $this->box['height'], imagecolorallocatealpha($this->im, rand(180, 255), rand(180, 255), rand(180, 255), 80));
     }
     $textHeight = count($lines) * $this->lineHeight;
     switch ($this->alignY) {
         case 'top':
             $yAlign = 0;
             break;
         case 'center':
             $yAlign = $this->box['height'] / 2 - $textHeight / 2;
             break;
         case 'bottom':
             $yAlign = $this->box['height'] - $textHeight;
             break;
     }
     $n = 0;
     foreach ($lines as $line) {
         $box = imageftbbox($this->fontSize, 0, $this->fontFace, $line);
         switch ($this->alignX) {
             case 'left':
                 $xAlign = 0;
                 break;
             case 'center':
                 $xAlign = ($this->box['width'] - ($box[2] - $box[0])) / 2;
                 break;
             case 'right':
                 $xAlign = $this->box['width'] - ($box[2] - $box[0]);
                 break;
         }
         $yShift = $this->lineHeight * $this->baseline;
         $xMOD = $this->box['x'] + $xAlign;
         $yMOD = $this->box['y'] + $yAlign + $yShift + $n * $this->lineHeight + $n * $this->leading;
         if ($this->debug == true) {
             imagefilledrectangle($this->im, $xMOD, $this->box['y'] + $yAlign + $n * $this->lineHeight + $n * $this->leading, $xMOD + ($box[2] - $box[0]), $this->box['y'] + $yAlign + $n * $this->lineHeight + $n * $this->leading + $this->lineHeight, $this->getColorIndex(array(rand(1, 180), rand(1, 180), rand(1, 180))));
         }
         if ($this->textShadow !== false) {
             imagefttext($this->im, $this->fontSize, 0, $xMOD + $this->textShadow['x'], $yMOD + $this->textShadow['y'], $this->textShadow['color'], $this->fontFace, $line);
         }
         imagefttext($this->im, $this->fontSize, 0, $xMOD, $yMOD, $this->fontColor, $this->fontFace, $line);
         $n++;
     }
 }
Example #20
0
 function calculate_font_box($text)
 {
     $font = $this->fonts_dir . $this->font;
     $rect = imageftbbox($this->font_size, 0, $font, $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 #21
0
 protected function getTextWidthHeight($text)
 {
     $position = imageftbbox($this->fontSize, 0, $this->font, $text);
     return array(self::WIDTH_KEY => $position[0] + abs($position[2]), self::HEIGHT_KEY => $position[1] + abs($position[5]));
 }
Example #22
0
 protected function calculateBox($text)
 {
     return imageftbbox($this->getFontSizeInPoints(), 0, $this->fontFace, $text);
 }
 /**
  * Generate image captcha
  *
  * Override this function if you want different image generator
  * Wave transform from http://www.captcha.ru/captchas/multiwave/
  *
  * @param string $id Captcha ID
  * @param string $word Captcha word
  */
 protected function _generateImage($id, $word)
 {
     if (!extension_loaded("gd")) {
         #require_once 'Zend/Captcha/Exception.php';
         throw new Zend_Captcha_Exception("Image CAPTCHA requires GD extension");
     }
     if (!function_exists("imagepng")) {
         #require_once 'Zend/Captcha/Exception.php';
         throw new Zend_Captcha_Exception("Image CAPTCHA requires PNG support");
     }
     if (!function_exists("imageftbbox")) {
         #require_once 'Zend/Captcha/Exception.php';
         throw new Zend_Captcha_Exception("Image CAPTCHA requires FT fonts support");
     }
     $font = $this->getFont();
     if (empty($font)) {
         #require_once 'Zend/Captcha/Exception.php';
         throw new Zend_Captcha_Exception("Image CAPTCHA requires font");
     }
     $w = $this->getWidth();
     $h = $this->getHeight();
     $fsize = $this->getFontSize();
     $img_file = $this->getImgDir() . $id . $this->getSuffix();
     if (empty($this->_startImage)) {
         $img = imagecreatetruecolor($w, $h);
     } else {
         $img = imagecreatefrompng($this->_startImage);
         if (!$img) {
             #require_once 'Zend/Captcha/Exception.php';
             throw new Zend_Captcha_Exception("Can not load start image");
         }
         $w = imagesx($img);
         $h = imagesy($img);
     }
     $text_color = imagecolorallocate($img, 0, 0, 0);
     $bg_color = imagecolorallocate($img, 255, 255, 255);
     imagefilledrectangle($img, 0, 0, $w - 1, $h - 1, $bg_color);
     $textbox = imageftbbox($fsize, 0, $font, $word);
     $x = ($w - ($textbox[2] - $textbox[0])) / 2;
     $y = ($h - ($textbox[7] - $textbox[1])) / 2;
     imagefttext($img, $fsize, 0, $x, $y, $text_color, $font, $word);
     // generate noise
     for ($i = 0; $i < $this->_dotNoiseLevel; $i++) {
         imagefilledellipse($img, mt_rand(0, $w), mt_rand(0, $h), 2, 2, $text_color);
     }
     for ($i = 0; $i < $this->_lineNoiseLevel; $i++) {
         imageline($img, mt_rand(0, $w), mt_rand(0, $h), mt_rand(0, $w), mt_rand(0, $h), $text_color);
     }
     // transformed image
     $img2 = imagecreatetruecolor($w, $h);
     $bg_color = imagecolorallocate($img2, 255, 255, 255);
     imagefilledrectangle($img2, 0, 0, $w - 1, $h - 1, $bg_color);
     // apply wave transforms
     $freq1 = $this->_randomFreq();
     $freq2 = $this->_randomFreq();
     $freq3 = $this->_randomFreq();
     $freq4 = $this->_randomFreq();
     $ph1 = $this->_randomPhase();
     $ph2 = $this->_randomPhase();
     $ph3 = $this->_randomPhase();
     $ph4 = $this->_randomPhase();
     $szx = $this->_randomSize();
     $szy = $this->_randomSize();
     for ($x = 0; $x < $w; $x++) {
         for ($y = 0; $y < $h; $y++) {
             $sx = $x + (sin($x * $freq1 + $ph1) + sin($y * $freq3 + $ph3)) * $szx;
             $sy = $y + (sin($x * $freq2 + $ph2) + sin($y * $freq4 + $ph4)) * $szy;
             if ($sx < 0 || $sy < 0 || $sx >= $w - 1 || $sy >= $h - 1) {
                 continue;
             } else {
                 $color = imagecolorat($img, $sx, $sy) >> 16 & 0xff;
                 $color_x = imagecolorat($img, $sx + 1, $sy) >> 16 & 0xff;
                 $color_y = imagecolorat($img, $sx, $sy + 1) >> 16 & 0xff;
                 $color_xy = imagecolorat($img, $sx + 1, $sy + 1) >> 16 & 0xff;
             }
             if ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255) {
                 // ignore background
                 continue;
             } elseif ($color == 0 && $color_x == 0 && $color_y == 0 && $color_xy == 0) {
                 // transfer inside of the image as-is
                 $newcolor = 0;
             } else {
                 // do antialiasing for border items
                 $frac_x = $sx - floor($sx);
                 $frac_y = $sy - floor($sy);
                 $frac_x1 = 1 - $frac_x;
                 $frac_y1 = 1 - $frac_y;
                 $newcolor = $color * $frac_x1 * $frac_y1 + $color_x * $frac_x * $frac_y1 + $color_y * $frac_x1 * $frac_y + $color_xy * $frac_x * $frac_y;
             }
             imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newcolor, $newcolor, $newcolor));
         }
     }
     // generate noise
     for ($i = 0; $i < $this->_dotNoiseLevel; $i++) {
         imagefilledellipse($img2, mt_rand(0, $w), mt_rand(0, $h), 2, 2, $text_color);
     }
     for ($i = 0; $i < $this->_lineNoiseLevel; $i++) {
         imageline($img2, mt_rand(0, $w), mt_rand(0, $h), mt_rand(0, $w), mt_rand(0, $h), $text_color);
     }
     imagepng($img2, $img_file);
     imagedestroy($img);
     imagedestroy($img2);
 }
Example #24
0
 function printErrors($Mode = "CLI")
 {
     if (count($this->Errors) == 0) {
         return 0;
     }
     if ($Mode == "CLI") {
         foreach ($this->Errors as $key => $Value) {
             echo $Value . "\r\n";
         }
     } elseif ($Mode == "GD") {
         $this->setLineStyle($Width = 1);
         $MaxWidth = 0;
         foreach ($this->Errors as $key => $Value) {
             $Position = imageftbbox($this->ErrorFontSize, 0, $this->ErrorFontName, $Value);
             $TextWidth = $Position[2] - $Position[0];
             if ($TextWidth > $MaxWidth) {
                 $MaxWidth = $TextWidth;
             }
         }
         $this->drawFilledRoundedRectangle($this->XSize - ($MaxWidth + 20), $this->YSize - (20 + ($this->ErrorFontSize + 4) * count($this->Errors)), $this->XSize - 10, $this->YSize - 10, 6, 233, 185, 185);
         $this->drawRoundedRectangle($this->XSize - ($MaxWidth + 20), $this->YSize - (20 + ($this->ErrorFontSize + 4) * count($this->Errors)), $this->XSize - 10, $this->YSize - 10, 6, 193, 145, 145);
         $C_TextColor = imagecolorallocate($this->Picture, 133, 85, 85);
         $YPos = $this->YSize - (18 + (count($this->Errors) - 1) * ($this->ErrorFontSize + 4));
         foreach ($this->Errors as $key => $Value) {
             imagettftext($this->Picture, $this->ErrorFontSize, 0, $this->XSize - ($MaxWidth + 15), $YPos, $C_TextColor, $this->ErrorFontName, $Value);
             $YPos = $YPos + ($this->ErrorFontSize + 4);
         }
     }
 }
Example #25
0
 public function make_watermark_text($text, $fontfile, $size = 16, $colour = "#ffffff", $angle = 0)
 {
     // check font file can be found
     if (!file_exists($fontfile)) {
         $this->set_error('Could not locate font file "' . $fontfile . '"');
         return $this;
     }
     // validate we loaded a main image
     if (!$this->_check_image()) {
         $remove = TRUE;
         // no image loaded so make temp image to use
         $this->main_image = imagecreatetruecolor(1000, 1000);
     } else {
         $remove = FALSE;
     }
     // work out text dimensions
     $bbox = imageftbbox($size, $angle, $fontfile, $text);
     $bw = abs($bbox[4] - $bbox[0]) + 1;
     $bh = abs($bbox[1] - $bbox[5]) + 1;
     $bl = $bbox[1];
     // use this to create watermark image
     if (is_resource($this->watermark_image)) {
         imagedestroy($this->watermark_image);
     }
     $this->watermark_image = imagecreatetruecolor($bw, $bh);
     // set colours
     $col = $this->_html2rgb($colour);
     $font_col = imagecolorallocate($this->watermark_image, $col[0], $col[1], $col[2]);
     $bg_col = imagecolorallocate($this->watermark_image, 127, 128, 126);
     // set method to use
     $this->watermark_method = 2;
     // create bg
     imagecolortransparent($this->watermark_image, $bg_col);
     imagefilledrectangle($this->watermark_image, 0, 0, $bw, $bh, $bg_col);
     // write text to watermark
     imagefttext($this->watermark_image, $size, $angle, 0, $bh - $bl, $font_col, $fontfile, $text);
     if ($remove) {
         imagedestroy($this->main_image);
     }
     return $this;
 }
Example #26
0
 /**
  * @param array $options
  *     'watermark' => waImage|string $watermark
  *     'opacity' => float|int 0..1
  *     'align' => self::ALIGN_* const
  *     'font_file' => null|string If null - will be used some default font. Note: use when watermark option is text
  *     'font_size' => float Size of font. Note: use when watermark option is text
  *     'font_color' => string Hex-formatted of color (without #). Note: use when watermark option is text
  *     'text_orientation' => self::ORIENTATION_* const. Note: use when watermark option is text
  * @throws waException
  * @return mixed
  */
 protected function _watermark($options)
 {
     $watermark = false;
     $opacity = 0.5;
     $align = self::ALIGN_BOTTOM_RIGHT;
     $font_file = null;
     $font_size = 12;
     $font_color = '888888';
     $text_orientation = self::ORIENTATION_HORIZONTAL;
     extract($options, EXTR_IF_EXISTS);
     $opacity = min(max($opacity, 0), 1);
     imagealphablending($this->image, true);
     if ($watermark instanceof waImage) {
         $type = $watermark->type;
         $gd_watermark = $this->createGDImageResourse($watermark->file, $type);
         $width = ifset($options['width'], $watermark->width);
         $height = ifset($options['height'], $watermark->height);
         $offset = $this->calcWatermarkOffset($width, $height, $align);
         if ($width != $watermark->width || $height != $watermark->height) {
             $watermark_resized = $this->_create($width, $height);
             if (function_exists('imagecopyresampled')) {
                 imagecopyresampled($watermark_resized, $gd_watermark, 0, 0, 0, 0, $width, $height, $watermark->width, $watermark->height);
             } else {
                 imagecopyresized($watermark_resized, $gd_watermark, 0, 0, 0, 0, $width, $height, $watermark->width, $watermark->height);
             }
             imagedestroy($gd_watermark);
             $gd_watermark = $watermark_resized;
         }
         imagecopymerge_alpha($this->image, $gd_watermark, $offset[0], $offset[1], 0, 0, $width, $height, $opacity * 100);
         imagedestroy($gd_watermark);
     } else {
         $text = (string) $watermark;
         if (!$text) {
             return;
         }
         $margin = round($font_size / 3.6);
         $font_color = array('r' => '0x' . substr($font_color, 0, 2), 'g' => '0x' . substr($font_color, 2, 2), 'b' => '0x' . substr($font_color, 4, 2), 'a' => floor((1 - $opacity) * 127));
         if ($align == self::ALIGN_CENTER) {
             $rotation = (int) ifempty($options['rotation'], 0);
             $text_orientation = self::ORIENTATION_HORIZONTAL;
         } else {
             if ($text_orientation == self::ORIENTATION_VERTICAL) {
                 $rotation = 90;
             } else {
                 $rotation = 0;
             }
         }
         if (!empty($font_file) && file_exists($font_file)) {
             $gd_info = gd_info();
             $gd_version = preg_replace('/[^0-9\\.]/', '', $gd_info['GD Version']);
             if (!empty($gd_info['FreeType Support']) && version_compare($gd_version, '2.0.1', '>=')) {
                 // Free Type
                 $free_type = true;
             } else {
                 // True Type
                 $free_type = false;
                 // GD1 use pixels, GD2 use points
                 if (version_compare($gd_version, '2.0', '<')) {
                     $font_size = 24 * $font_size / 18;
                     // 24px = 18pt
                 }
             }
             if ($free_type) {
                 $metrics = imageftbbox($font_size, 0, $font_file, $text);
             } else {
                 $metrics = imagettfbbox($font_size, 0, $font_file, $text);
             }
             if ($metrics) {
                 $width = $metrics[2] - $metrics[0];
                 $height = $metrics[1] - $metrics[7];
                 if ($text_orientation == self::ORIENTATION_VERTICAL) {
                     list($width, $height) = array($height, $width);
                 }
                 $offset = $this->calcWatermarkOffset($width, $height, $align, $margin);
                 $offset = $this->watermarkOffsetFix($offset, $width, $height, $align, $text_orientation, $align == self::ALIGN_CENTER ? $rotation : 0);
                 $color = imagecolorallocatealpha($this->image, $font_color['r'], $font_color['g'], $font_color['b'], $font_color['a']);
                 if ($free_type) {
                     imagefttext($this->image, $font_size, $rotation, $offset[0], $offset[1], $color, $font_file, $text);
                 } else {
                     imagettftext($this->image, $font_size, $rotation, $offset[0], $offset[1], $color, $font_file, $text);
                 }
             } else {
                 throw new waException(_ws("Can't read font file {$font_file}"));
             }
         } else {
             $font = floor(5 * $font_size / 12);
             if ($font < 1) {
                 $font = 1;
             } else {
                 if ($font > 5) {
                     $font = 5;
                 }
             }
             $width = imagefontwidth($font) * strlen($text);
             $height = imagefontheight($font);
             if ($text_orientation == self::ORIENTATION_VERTICAL) {
                 list($width, $height) = array($height, $width);
             }
             $offset = $this->calcWatermarkOffset($width, $height, $align, $margin);
             if ($rotation != 0) {
                 imagestring_rotate($this->image, $font, $rotation, $offset[0], $offset[1], $text, $font_color['r'], $font_color['g'], $font_color['b'], $font_color['a']);
             } else {
                 $color = imagecolorallocatealpha($this->image, $font_color['r'], $font_color['g'], $font_color['b'], $font_color['a']);
                 imagestring($this->image, $font, $offset[0], $offset[1], $text, $color);
             }
         }
     }
 }
Example #27
0
$l3 = strtoupper(createKey(1, 1));
$l4 = strtoupper(createKey(1, 1));
$verify_string = $l1 . ' ' . $l2 . ' ' . $l3 . ' ' . $l4;
$real_string = $l1 . $l2 . $l3 . $l4;
$verify_code = sha1(strtoupper($real_string) . SECRET_KEY);
$_SESSION['verify_code'] = $verify_code;
function makeRBGColor($color, $image)
{
    $color = str_replace("#", "", $color);
    $red = hexdec(substr($color, 0, 2));
    $green = hexdec(substr($color, 2, 2));
    $blue = hexdec(substr($color, 4, 2));
    $out = ImageColorAllocate($image, $red, $green, $blue);
    return $out;
}
$wordBox = imageftbbox($fontSize, 0, $font, $verify_string);
$wordBoxWidth = $wordBox[2];
$wordBoxHeight = $wordBox[1] + abs($wordBox[7]);
$containerWidth = $wordBoxWidth + $padding * 2;
$containerHeight = $wordBoxHeight + $padding * 2;
$textX = $padding;
$textY = $containerHeight - $padding;
$captchaImage = imagecreate($containerWidth, $containerHeight);
$red = randColor();
$green = randColor();
$blue = randColor();
$backgroundColor = ImageColorAllocate($captchaImage, $red, $green, $blue);
$rred = 255 - $red;
$rgreen = 255 - $green;
$rblue = 255 - $blue;
$textColor = ImageColorAllocate($captchaImage, $rred, $rgreen, $rblue);
Example #28
0
 /**
  * Draws the captcha code on the image
  */
 protected function drawWord()
 {
     $width2 = $this->image_width * $this->iscale;
     $height2 = $this->image_height * $this->iscale;
     if (!is_readable($this->ttf_file)) {
         imagestring($this->im, 4, 10, $this->image_height / 2 - 5, 'Failed to load TTF font file!', $this->gdtextcolor);
     } else {
         if ($this->perturbation > 0) {
             $font_size = $height2 * 0.4;
             $bb = imageftbbox($font_size, 0, $this->ttf_file, $this->code_display);
             $tx = $bb[4] - $bb[0];
             $ty = $bb[5] - $bb[1];
             $x = floor($width2 / 2 - $tx / 2 - $bb[0]);
             $y = round($height2 / 2 - $ty / 2 - $bb[1]);
             imagettftext($this->tmpimg, $font_size, 0, $x, $y, $this->gdtextcolor, $this->ttf_file, $this->code_display);
         } else {
             $font_size = $this->image_height * 0.4;
             $bb = imageftbbox($font_size, 0, $this->ttf_file, $this->code_display);
             $tx = $bb[4] - $bb[0];
             $ty = $bb[5] - $bb[1];
             $x = floor($this->image_width / 2 - $tx / 2 - $bb[0]);
             $y = round($this->image_height / 2 - $ty / 2 - $bb[1]);
             imagettftext($this->im, $font_size, 0, $x, $y, $this->gdtextcolor, $this->ttf_file, $this->code_display);
         }
     }
     // DEBUG
     //$this->im = $this->tmpimg;
     //$this->output();
 }
Example #29
0
    default:
        $MainText->value = "Not available anymore";
        $MainText->size = 180;
        $Info->value = "Go check Updates";
        $Info->size = 150;
        $MainText->angle = 1;
        $Info->angle = 1;
        $FinalHeight = 50;
        break;
}
$size = imageftbbox($MainText->size, $MainText->angle, $MainText->font, $MainText->value);
$MainText->initiate($size);
$MainText->x = 0;
$MainText->y = $MainText->height;
if ($Info->value != "") {
    $size = imageftbbox($Info->size, $Info->angle, $Info->font, $Info->value);
    $Info->initiate($size);
    $Info->x = 0;
    $Info->y = $MainText->height + $Info->height;
}
$Image = new Text();
$Image->width = max($MainText->width, $Info->width);
$Image->height = $MainText->height;
$Image->height += $Info->height;
$MainText->x = max(0, floor(($Image->width - $MainText->width) / 2));
$MainText->y = 0;
$Info->x = max(0, floor(($Image->width - $Info->width) / 2));
$Info->y = $MainText->height + 1;
$img = imagecreatetruecolor($Image->width, $Image->height);
if (isset($TrueFalse) && $TrueFalse > 3000) {
    $MainText->color = imagecolorallocate($img, 0, 0, 0);
Example #30
0
            if ($i != 0) {
                imagefttext($image, '7', 0, $j * $iBarWidth + 100 + 2, $imgHeight - $iHeight - $graphValues[$i][$j] * ($i == 0 ? $bmpl : $mpl) - 12, $color, $sFont, round($graphValues2[$i][$j] / $addD) . "\n" . $graphValues3[$i][$j]);
            } else {
                $iCount = 0;
                for ($k = 1; $k < count($graphValues2); $k++) {
                    $addD = $k == 18 ? 2 : 1;
                    if (!in_array($graphStyle[$k]['op_codes'][0], array('p0', 'p1', 'p2', 'p3')) && !in_array($k, $graphStyleSummIgnor)) {
                        $iCount += round($graphValues2[$k][$j] / $addD, 1);
                    }
                }
                imagefttext($image, '7', 0, $j * $iBarWidth + 100 + 2, $imgHeight - $iHeight - $graphValues[$i][$j] * ($i == 0 ? $bmpl : $mpl) - 12, $color, $sFont, round($graphValues2[$i][$j] / $addD, 1) . "\n" . $iCount);
            }
        }
    }
    $iFontSizeTitle = 8;
    $aBox = imageftbbox($iFontSizeTitle, 0, $sFont, $graphStyle[$i]['text']);
    $width = abs($aBox[0]) + abs($aBox[2]);
    imagefttext($image, $iFontSizeTitle, 0, 92 - $width, $imgHeight - $iHeight, $graphStyle[$i]['color'], $sFont, $graphStyle[$i]['text']);
}
$aMonthes[1] = 'Январь';
$aMonthes[2] = 'Февраль';
$aMonthes[3] = 'Март';
$aMonthes[4] = 'Апрель';
$aMonthes[5] = 'Май';
$aMonthes[6] = 'Июнь';
$aMonthes[7] = 'Июль';
$aMonthes[8] = 'Август';
$aMonthes[9] = 'Сентябрь';
$aMonthes[10] = 'Октябрь';
$aMonthes[11] = 'Ноябрь';
$aMonthes[12] = 'Декабрь';