Ejemplo n.º 1
0
function JPGText($str, $fontname, $fontsize, $backcol, $txtcol)
{
    global $layout;
    Header("Last-Modified: " . gmDate("D, d M Y H:i:s", Time()) . " GMT");
    Header("Expires: " . gmDate("D, d M Y H:i:s", Time() - 3601) . " GMT");
    Header("Pragma: no-cache");
    Header("Cache-control: no-cache");
    Header("Content-Type: image/jpeg");
    $a = ImageTTFBBox($fontsize, 0, $fontname, $str);
    $width = $a[2] + 4;
    $bla = get_maximum_height($fontname, $fontsize);
    $height = $bla[0] + 3;
    $bl = $bla[1];
    $im = ImageCreate($width, $height);
    $bgcol = ImageColorAllocate($im, $backcol['red'], $backcol['green'], $backcol['blue']);
    $fgcol = ImageColorAllocate($im, $txtcol['red'], $txtcol['green'], $txtcol['blue']);
    if (!function_exists(imagegif)) {
        imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str);
        imagejpeg($im, "", 80);
    } else {
        ImageColorTransparent($im, $bgcol);
        imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str);
        imagegif($im);
    }
    ImageDestroy($im);
}
Ejemplo n.º 2
0
function code()
{
    $fontSize = 20;
    //定义字体大小
    $length = 5;
    //定义字符串长度
    $strNum = GetVerify($length);
    //获取一个随机字符串
    $_SESSION['verify'] = $strNum;
    //付值给session
    $width = 90;
    //定义图片宽度
    $height = 30;
    //定义图片高度
    $im = imagecreate($width, $height);
    //生成一张指定宽高的图片
    $backgroundcolor = imagecolorallocate($im, 255, 255, 255);
    //生成背景色
    $frameColor = imageColorAllocate($im, 150, 150, 150);
    //生成边框色
    $font = './system/fonts/arial.ttf';
    //提取字体文件,开始写字
    for ($i = 0; $i < $length; $i++) {
        $charY = ($height + 9) / 2 + rand(-1, 1);
        //定义字符Y坐标
        $charX = $i * 15 + 8;
        //定义字符X坐标
        //生成字符颜色
        $text_color = imagecolorallocate($im, mt_rand(50, 200), mt_rand(50, 128), mt_rand(50, 200));
        $angle = rand(-20, 20);
        //生成字符角度
        //写入字符
        imageTTFText($im, $fontSize, $angle, $charX, $charY, $text_color, $font, $strNum[$i]);
    }
    for ($i = 0; $i <= 5; $i++) {
        //循环画背景线
        $linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        $linex = mt_rand(1, $width - 1);
        $liney = mt_rand(1, $height - 1);
        imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
    }
    for ($i = 0; $i <= 32; $i++) {
        //循环画背景点,生成麻点效果
        $pointcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        imagesetpixel($im, mt_rand(1, $width - 1), mt_rand(1, $height - 1), $pointcolor);
    }
    imagerectangle($im, 0, 0, $width - 1, $height - 1, $frameColor);
    //画边框
    //ob_clean();
    //header('Content-type: image/png');
    imagepng($im);
    imagedestroy($im);
    return $strNum;
}
Ejemplo n.º 3
0
function textToImg($text, $backRGB, $strRGB, $fontPath, $fontSize, $margin)
{
    // 大きさを測定
    $result = imageTTFBBox($fontSize, 0, $fontPath, $text);
    // 幅と高さを取得
    $width = abs($result[4]) + abs($result[6]) + $margin * 2;
    $height = abs($result[1]) + abs($result[7]) + $margin * 2;
    // イメージリソースを生成
    $img = imageCreateTrueColor($width, $height);
    // 色を生成
    $backColor = imageColorAllocate($img, $backRGB['red'], $backRGB['green'], $backRGB['blue']);
    $strColor = imageColorAllocate($img, $strRGB['red'], $strRGB['green'], $strRGB['blue']);
    // 背景を塗りつぶす
    imageFilledRectangle($img, 0, 0, $width, $height, $backColor);
    // 文字を描く
    imageTTFText($img, $fontSize, 0, $margin + abs($result[0]), $margin + abs($result[7]), $strColor, $fontPath, $text);
    return $img;
}
Ejemplo n.º 4
0
/**
 * 文字画像出力
 **/
function outPNG($dir, $font, $text, $name)
{
    $width = 80;
    $height = 90;
    $fontSize = 60;
    $fangle = 0;
    $img = imagecreate($width, $height);
    $black = ImageColorAllocate($img, 0x0, 0x0, 0x0);
    $white = ImageColorAllocate($img, 0xff, 0xff, 0xff);
    //imagealphablending($img, true);
    //imagesavealpha($img, true);
    ImageFilledRectangle($img, 0, 0, $width, $height, $white);
    imagecolortransparent($img, $white);
    $box = imagettfbbox($fontSize, 0, $font, $text);
    $x = 0;
    $y = 70;
    imageTTFText($img, $fontSize, $fangle, $x, $y, $black, $font, $text);
    $filename = $dir . "/" . $name . ".png";
    imagepng($img, $filename);
    imagedestroy($img);
}
 /**
  * @param $backgroundStyle
  * @param $bgColor2
  */
 private function drawBG($backgroundStyle, $bgColor2)
 {
     // Draw some random chars into the background. Unlike the other GD drawing functions
     // (imageFilledArc, imageFilledPolygon etc.) imageTTFText is anti-aliased.
     $sizeFactor = $this->width / 40;
     switch ($backgroundStyle) {
         case 0:
             imageTTFText($this->avatar, 170 * $sizeFactor, 10, 0, 35 * $sizeFactor, $bgColor2, $this->fontFace, 'O');
             break;
         case 1:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, 'o');
             break;
         case 2:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 30 * $sizeFactor, $bgColor2, $this->fontFace, '>');
             break;
         case 3:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, '//');
             break;
         case 4:
             imageTTFText($this->avatar, 90 * $sizeFactor, -60, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, ')');
             break;
         case 5:
             imageTTFText($this->avatar, 120 * $sizeFactor, -20, -30 * $sizeFactor, 20 * $sizeFactor, $bgColor2, $this->fontFace, '=');
             break;
         case 6:
             imageTTFText($this->avatar, 120 * $sizeFactor, -20, -45 * $sizeFactor, 25 * $sizeFactor, $bgColor2, $this->fontFace, '=');
             break;
         case 7:
             imageTTFText($this->avatar, 100 * $sizeFactor, -20, -45 * $sizeFactor, 25 * $sizeFactor, $bgColor2, $this->fontFace, 'Z');
             break;
         case 8:
             imageTTFText($this->avatar, 140 * $sizeFactor, -20, -45 * $sizeFactor, 25 * $sizeFactor, $bgColor2, $this->fontFace, '#');
             break;
         case 9:
             imageTTFText($this->avatar, 90 * $sizeFactor, -25, -40 * $sizeFactor, 25 * $sizeFactor, $bgColor2, $this->fontFace, '#');
             break;
     }
 }
Ejemplo n.º 6
0
 /**
  * Draws the legend key at the specific location.
  * @param int $x The x coordinate for the key's top, left corner.
  * @param int $y The y coordinate for the key's top, left corner.
  * @param object $color The GD colour identifier, created with imageColorAllocate().
  * @param string $label
  * @param int $squareSize The size of the square, in pixels.
  * @param int $labelPadding
  * @param int $fontSize
  */
 protected function _drawLegendKey($x, $y, $color, $label, $squareSize, $labelPadding, $fontSize)
 {
     $labelX = $x + $squareSize + $labelPadding;
     // Centre the label vertically to the square.
     $labelBBox = imageTTFBBox($fontSize, 0, $this->legendFont, $label);
     $labelHeight = abs($labelBBox[7] - $labelBBox[1]);
     $labelY = $y + $squareSize / 2 - $labelHeight / 2;
     imageFilledRectangle($this->canvas, $x, $y, $x + $squareSize, $y + $squareSize, $this->_convertColor($color));
     imageTTFText($this->canvas, $fontSize, 0, $labelX + abs($labelBBox[0]), $labelY + abs($labelBBox[7]), $this->_convertColor($this->textColor), $this->legendFont, $label);
 }
Ejemplo n.º 7
0
	function	txt2img()
	{
		$hImg_temp = imageCreate( 10, 10 );
		$txt_color = $this->txtcolor( $hImg_temp );
		$p4 = imageTTFText( $hImg_temp, $this->font_size, 0, 0, 0, $txt_color, $this->ttf_font, $this->text );
		imageDestroy( $hImg_temp );
		
		$margin = 4 ;
		$x_size = ($p4[2]-$p4[0]) + $margin ;
		$y_size = $p4[1]-$p4[7] + $margin ;
		$this->hTxt = imageCreate( $x_size, $y_size );
		//$hTxt = imageCreate( 600, 300 );
		$bg_color = imageColorAllocate( $this->hTxt, 200, 200, 200 );
		imageFill( $this->hTxt, 0, 0, $bg_color );
		imageColorTransparent( $this->hTxt, $bg_color );
		$x = 0+floor($margin/2) ;
		$y = $y_size-floor($margin/2);
		$txt_color = $this->txtcolor( $this->hTxt );
		imageTTFText( $this->hTxt, $this->font_size, 0, $x, $y, $txt_color, $this->ttf_font, $this->text );
		//$txt_shadow = imageColorAllocate( $hTxt, 100, 100, 100 );
		//imageTTFText( $hTxt, $this->font_size, 0, $x-1, $y-1, $txt_shadow, $this->ttf_font, $this->text );
		//return $hTxt ;
	}
Ejemplo n.º 8
0
 /**
  * @ignore
  */
 private function _generateImageFromText(&$width, &$height)
 {
     if (FALSE === $this->is_ready()) {
         return FALSE;
     }
     if (!empty($this->h_wmimage)) {
         // Already have The image
         return TRUE;
     }
     //
     // Generate a transparent PNG image type thing
     // with the text we want
     //
     // First find the bounding box
     $this->t_wmsize = imageftbbox($this->_text_size, $this->_text_angle, $this->_text_font, $this->_text);
     $width = abs($this->t_wmsize[0]) + abs($this->t_wmsize[2]);
     $height = abs($this->t_wmsize[1]) + abs($this->t_wmsize[5]);
     $image = imagecreatetruecolor($width + $this->_hmargin, $height + $this->_vmargin);
     $this->h_bgcolor = imagecolorallocate($image, $this->_bg_color[0], $this->_bg_color[1], $this->_bg_color[2]);
     // background
     imagefilledrectangle($image, 0, 0, $width - 1 + $this->_hmargin, $height - 1 + $this->_vmargin, $this->h_bgcolor);
     if ($this->_transparent) {
         // make the background transparent.
         imagecolortransparent($image, $this->h_bgcolor);
     }
     // draw the forgeround text
     $this->h_textcolor = imagecolorallocate($image, $this->_text_color[0], $this->_text_color[1], $this->_text_color[2]);
     $res = imageTTFText($image, $this->_text_size, $this->_text_angle, (int) ($this->_hmargin / 2) + 1, $height + (int) ($this->_vmargin / 2), $this->h_textcolor, $this->_text_font, $this->_text);
     $width += $this->_hmargin;
     $height += $this->_vmargin;
     // should have a nice image now.
     return $image;
 }
Ejemplo n.º 9
0
    }
    // Font
    if ($txt_use_random_font) {
        $font = $txt_font_dir . b1n_arrayRand($txt_fonts);
        if (!file_exists($font)) {
            $font = $txt_font_dir . $txt_fonts[0];
        }
    } else {
        $font = $txt_font_dir . $txt_fonts[0];
    }
    // Color
    if ($txt_use_random_color) {
        $r = rand($txt_rgb_min, $txt_rgb_max);
        $g = rand($txt_rgb_min, $txt_rgb_max);
        $b = rand($txt_rgb_min, $txt_rgb_max);
        $color = imageColorAllocate($img, $r, $g, $b);
    } else {
        $color = $black;
    }
    imageTTFText($img, $txt_font_size, $angle, $position, $txt_vertical_pos, $color, $font, $c);
    $position += $txt_letter_spacing_inc;
}
// Saving string in session
$_SESSION['seccode'] = b1n_crypt(strToLower($string));
// Showing image
header('Content-type: image/jpeg');
imageJpeg($img);
imageDestroy($img);
?>
 
Ejemplo n.º 10
0
$strNum = GetVerify($length);											//ȡһַ
$_SESSION['verifys'] = $strNum;									//ֵsession
$width = 80;													//ͼƬ
$height = 25;													//ͼƬ߶
$im = imagecreate($width,$height);									//һָߵͼƬ
$backgroundcolor = imagecolorallocate ($im, 255, 255, 255);				//ɱɫ
$frameColor = imageColorAllocate($im, 150, 150, 150);					//ɱ߿ɫ
$font = realpath("./Plugs/ARIAL.TTF");						//ȡļʼд
for($i = 0; $i < $length; $i++) {
	$charY = ($height+9)/2 + rand(-1,1);								//ַY
	$charX = $i*15+22;											//ַX
															//ַɫ
	$text_color = imagecolorallocate($im, mt_rand(50, 200), mt_rand(50, 128), mt_rand(50, 200));
	$angle = rand(-20,20);										//ַǶ
															//дַ
	imageTTFText($im, $fontSize, $angle, $charX,  $charY, $text_color, $font, $strNum[$i]);
}
for($i=0; $i <= 5; $i++) {											//ѭ
	$linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
	$linex = mt_rand(1, $width-1);
	$liney = mt_rand(1, $height-1);
	imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
}
for($i=0; $i <= 32; $i++) {											//ѭ,Ч
	$pointcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
	imagesetpixel($im, mt_rand(1, $width-1), mt_rand(1, $height-1), $pointcolor);
}
imagerectangle($im, 0, 0, $width-1 , $height-1 , $frameColor);				//߿
ob_clean();
header('Content-type: image/png');
imagepng($im);
Ejemplo n.º 11
0
 protected function create_images($text, $hash)
 {
     // Check parameters.
     if (trim($text) === '') {
         return array();
     }
     if (!mb_check_encoding($text, 'UTF-8')) {
         throw new IMGTextException('String is not valid UTF-8');
     }
     $font_filename = $this->font_dir . '/' . $this->font_name . '.' . $this->font_ext;
     if (!file_exists($font_filename)) {
         throw new IMGTextException('Font not found: ' . $font);
     }
     $font_size = (int) $this->font_size;
     if ($font_size <= 0) {
         throw new IMGTextException('Invalid font size: ' . $size);
     }
     if (!preg_match('/^#?(?:[0-9a-f]{3})(?:[0-9a-f]{3})?$/', $this->color)) {
         throw new IMGTextException('Invalid text color: ' . $this->color);
     }
     if ($this->background_color !== false && !preg_match('/^#?(?:[0-9a-f]{3})(?:[0-9a-f]{3})?$/', $this->background_color)) {
         throw new IMGTextException('Invalid background color: ' . $this->background_color);
     }
     if (!is_array($this->padding) || count($this->padding) != 4) {
         throw new IMGTextException('Invalid padding. Please use array with 4 members.');
     }
     if (!is_array($this->shadow_offset) || count($this->shadow_offset) != 2) {
         throw new IMGTextException('Invalid shadow offset. Please use array with 2 members.');
     }
     if ($this->shadow_opacity < 0 || $this->shadow_opacity > 127) {
         throw new IMGTextException('Invalid shadow opacity. Please use a value between 0 (opaque) and 127 (transparent).');
     }
     // Split the text into words.
     $words = preg_split('/\\s+/u', $text);
     // Parse the padding amount.
     $padding_top = intval($this->padding[0]);
     $padding_right = intval($this->padding[1]);
     $padding_bottom = intval($this->padding[2]);
     $padding_left = intval($this->padding[3]);
     // Get size information for each word. We do this first, in order to find out the maximum height.
     $fragments = array();
     $max_height = 0;
     $max_top = 0;
     foreach ($words as $w) {
         $w = trim($w);
         if ($w === '') {
             continue;
         }
         // Get the bounding box size.
         $bounds = imageTTFBBox($font_size, 0, $font_filename, $w);
         // Get more useful information from GD's return values.
         $width = $bounds[2] - $bounds[0];
         $height = $bounds[3] - $bounds[5];
         $left = -$bounds[6] - 1;
         $top = -$bounds[7] - 1;
         // Update the max height/top values if necessary.
         if ($height > $max_height) {
             $max_height = $height;
         }
         if ($top > $max_top) {
             $max_top = $top;
         }
         $fragments[] = array($w, $width, $height, $left, $top);
     }
     // Create images for each word.
     $count = 1;
     $return = array();
     foreach ($fragments as $f) {
         list($w, $width, $height, $left, $top) = $f;
         $img_width = $width + $padding_left + $padding_right;
         $img_height = $this->image_height ? $this->image_height : $max_height + $padding_top + $padding_bottom;
         $text_left = $left + $padding_left;
         $text_top = $max_top + $padding_top;
         // Adjust image size and text location if there's a shadow.
         if ($this->shadow) {
             if ($this->shadow_offset[0] < 0) {
                 $shadow_space_left = $this->shadow_blur - $this->shadow_offset[0];
                 $shadow_space_right = max(0, $this->shadow_blur + abs($this->shadow_offset[0]));
                 $shadow_left = $text_left + $shadow_space_left;
                 $text_left = $text_left + $shadow_space_left - $this->shadow_offset[0];
             } else {
                 $shadow_space_left = max(0, $this->shadow_blur - $this->shadow_offset[0]);
                 $shadow_space_right = $this->shadow_blur + $this->shadow_offset[0];
                 $shadow_left = $text_left + $shadow_space_left + $this->shadow_offset[0];
                 $text_left = $text_left + $shadow_space_left;
             }
             if ($this->shadow_offset[1] < 0) {
                 $shadow_space_top = $this->shadow_blur - $this->shadow_offset[1];
                 $shadow_space_bottom = max(0, $this->shadow_blur + abs($this->shadow_offset[1]));
                 $shadow_top = $text_top + $shadow_space_top;
                 $text_top = $text_top + $shadow_space_top - $this->shadow_offset[1];
             } else {
                 $shadow_space_top = max(0, $this->shadow_blur - $this->shadow_offset[1]);
                 $shadow_space_bottom = $this->shadow_blur + $this->shadow_offset[1];
                 $shadow_top = $text_top + $shadow_space_top + $this->shadow_offset[1];
                 $text_top = $text_top + $shadow_space_top;
             }
             $img_width += $shadow_space_left + $shadow_space_right;
             $img_height += $shadow_space_top + $shadow_space_bottom;
         }
         // Initialize the image and draw the background.
         $img = imageCreateTrueColor($img_width, $img_height);
         if ($this->background_color === false) {
             imageSaveAlpha($img, true);
             imageAlphaBlending($img, false);
             $img_background_color = imageColorAllocateAlpha($img, 255, 255, 255, 127);
             imageFilledRectangle($img, 0, 0, $img_width, $img_height, $img_background_color);
             imageAlphaBlending($img, true);
         } else {
             $img_background_colors = $this->hex2rgb($this->background_color);
             $img_background_color = imageColorAllocate($img, $img_background_colors[0], $img_background_colors[1], $img_background_colors[2]);
             imageFilledRectangle($img, 0, 0, $img_width, $img_height, $img_background_color);
         }
         // Draw the shadow.
         if ($this->shadow) {
             // Blurred shadow on a transparent background needs special treatment because of GD's limitations.
             if ($this->shadow_blur && $this->background_color === false) {
                 // Create a temporary image for the shadow.
                 $temp = imageCreateTrueColor($img_width, $img_height);
                 imageSaveAlpha($temp, true);
                 imageFilledRectangle($temp, 0, 0, $img_width, $img_height, imageColorAllocate($temp, 127, 127, 127));
                 // Draw the shadow text on the temporary image, and blur it.
                 $temp_text_color = imageColorAllocate($temp, $this->shadow_opacity, $this->shadow_opacity, $this->shadow_opacity);
                 imageTTFText($temp, $font_size, 0, $shadow_left, $shadow_top, $temp_text_color, $font_filename, $w);
                 for ($i = 0; $i < $this->shadow_blur; $i++) {
                     imageFilter($temp, IMG_FILTER_GAUSSIAN_BLUR);
                 }
                 // Use the blurred shadow as an alpha mask on the original image.
                 $shadow_colors = $this->hex2rgb($this->shadow_color);
                 for ($x = 0; $x < $img_width; $x++) {
                     for ($y = 0; $y < $img_height; $y++) {
                         $alpha = imageColorAt($temp, $x, $y) & 0xff;
                         imageSetPixel($img, $x, $y, imageColorAllocateAlpha($img, $shadow_colors[0], $shadow_colors[1], $shadow_colors[2], $alpha));
                     }
                 }
                 imageDestroy($temp);
             } else {
                 $shadow_colors = $this->hex2rgb($this->shadow_color);
                 $shadow_color = imageColorAllocateAlpha($img, $shadow_colors[0], $shadow_colors[1], $shadow_colors[2], $this->shadow_opacity);
                 imageTTFText($img, $font_size, 0, $shadow_left, $shadow_top, $shadow_color, $font_filename, $w);
                 for ($i = 0; $i < $this->shadow_blur; $i++) {
                     imageFilter($img, IMG_FILTER_GAUSSIAN_BLUR);
                 }
             }
         }
         // Draw the word.
         $text_colors = $this->hex2rgb($this->color);
         $text_color = imageColorAllocate($img, $text_colors[0], $text_colors[1], $text_colors[2]);
         imageTTFText($img, $font_size, 0, $text_left, $text_top, $text_color, $font_filename, $w);
         // Save to a PNG file.
         $filename = '/imgtext.' . $hash . '.word-' . str_pad($count, 3, '0', STR_PAD_LEFT) . '.png';
         imagePNG($img, $this->cache_local_dir . $filename);
         imageDestroy($img);
         // Add information about this word to the return array.
         $return[] = array('word' => $w, 'path' => $this->cache_url_prefix . $filename);
         $count++;
     }
     // Returns a list of dictionaries, each containing a word and the corresponding image URL.
     return $return;
 }
Ejemplo n.º 12
0
 /**
  * Create a GD image with text.
  *
  * @param   string    $text        The text to use. TTF fonts accept HTML character codes.
  * @param   integer   $size        Fontsize in pixels. For non-truetype fonts, size has a range of [1-5] points.
  * @param   integer   $padding     Padding in pixels arround the text
  * @param   string    $color       Color of the text
  * @param   string    $background  Background for the text. Default is transparent background.
  * @param   integer   $radius      Radius of rounded corners ont eh background if desired
  * @return  resource               GD resource with text.
  */
 public function text_image($text, $size = 24, $padding = 0, $color = "#ffffff", $background = 'transparent', $radius = 10)
 {
     if ($this->ttfont) {
         # Decode any htmls special chars, insert copyright date
         $text = html_entity_decode($text) . ' ' . chr(169) . date('Y');
         # Get our bounding box coordinates to find width and height.
         $bbox = imagettfbbox($size, 0, $this->ttfont, $text);
         $w = abs($bbox[4] - $bbox[0]) + $padding * 2;
         $h = abs($bbox[5] - $bbox[0]) + $padding * 2;
         # Center horizontally
         $x = $padding;
         # Center vertically
         $y = $h - $padding;
     } else {
         # Insert copyright date
         $text = $text . ' (c)' . date('Y');
         $size = Number::minmax($size, 1, 5);
         $w = imagefontwidth($size) * strlen($text) + 2 * $padding;
         $h = imagefontheight($size) + 2 * $padding;
         # Center horizontally, vertically
         $x = $y = $padding;
     }
     # Blank canvas
     $stamp = imagecreatetruecolor($w, $h);
     # Allocate Transparent background
     imagefill($stamp, 0, 0, imagecolorallocatealpha($stamp, 0, 0, 0, 127));
     # Add (rounded) rectangle to background if desired
     if ($background != 'transparent') {
         $this->imagefillroundedrect($stamp, 0, 0, $w, $h, $radius, $background, 1);
     }
     # Allocate Text Color
     $tcol = Color::hex2rgb($color);
     $tcol = imagecolorallocatealpha($stamp, $tcol[0], $tcol[1], $tcol[2], 0);
     # Allocate text using Truetype font if available
     if ($this->ttfont) {
         imageTTFText($stamp, $size, 0, $x, $y, $tcol, $this->ttfont, $text);
     } else {
         imagestring($stamp, $size, $x, $y, $text, $tcol);
     }
     return $stamp;
 }
Ejemplo n.º 13
0
<?php

// Create the canvas
$canvas = imagecreate(150, 80);
// First colour - this will be the default colour for the canvas
$light_blue = imagecolorallocate($canvas, 176, 226, 255);
// The second colour - to be used for the text
$black = imagecolorallocate($canvas, 0, 0, 0);
// Path to the font you are going to use
$font = "verdana.ttf";
// Text to write
$text = "Text";
// Font size
$size = "40";
// Add the text to the canvas
imageTTFText($canvas, $size, 0, 15, 60, $black, $font, $text);
// Save as Text.jpg
imagejpeg($canvas, "Text.jpg");
// Clear the memory of the tempory image
ImageDestroy($canvas);
Ejemplo n.º 14
0
 public function getPNG()
 {
     // создаем картинку
     $image = imageCreate($this->width + $this->widthLegend, $this->height);
     $backColor = imageColorAllocate($image, $this->colorBG >> 16, ($this->colorBG >> 8) % 256, $this->colorBG % 256);
     $centerColor = imageColorAllocate($image, $this->colorCenter >> 16, ($this->colorCenter >> 8) % 256, $this->colorCenter % 256);
     $pointsColor = imageColorAllocate($image, $this->colorPoints >> 16, ($this->colorPoints >> 8) % 256, $this->colorPoints % 256);
     $legendColor = imageColorAllocate($image, $this->colorLegend >> 16, ($this->colorLegend >> 8) % 256, $this->colorLegend % 256);
     // background
     imageFilledRectangle($image, 0, 0, $this->width, $this->height, $backColor);
     imageRectangle($image, $this->width, 0, $this->widthLegend + $this->width - 1, $this->height - 1, $legendColor);
     // добавляем масштаб в легенду
     imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2 - 1, $this->width + 10, $this->height - $this->fontSize * 2 + 1, $legendColor);
     imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2, $this->width + 20, $this->height - $this->fontSize * 2, $legendColor);
     imageLine($image, $this->width + 20, $this->height - $this->fontSize * 2 - 1, $this->width + 20, $this->height - $this->fontSize * 2 + 1, $legendColor);
     imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize + 20, $this->height - $this->fontSize * 1.5, $legendColor, $this->pathToFont, "{$this->metersIn10Pix} {$this->metersLabel}");
     // center
     imageFilledEllipse($image, $this->centerWidth, $this->centerHeight, $this->sizePoints, $this->sizePoints, $centerColor);
     imageTTFText($image, $this->fontSize, 0, $this->centerWidth, $this->centerHeight + $this->fontSize + $this->sizePoints, $centerColor, $this->pathToFont, "0");
     imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2, $legendColor, $this->pathToFont, "0 - {$this->centerLabel}");
     // points
     $i = 1;
     foreach ($this->pointsBased as $v) {
         $angle = $v->getPoint()->getAzimuth() - 90;
         // угол для тригонометрии
         $pointWidth = $this->centerWidth + $this->k * ($v->getPoint()->getDistance() * cos(deg2rad($angle)));
         $pointHeight = $this->centerHeight + $this->k * ($v->getPoint()->getDistance() * sin(deg2rad($angle)));
         // рисуем точку
         imageEllipse($image, $pointWidth, $pointHeight, $this->sizePoints, $this->sizePoints, $pointsColor);
         // подпись
         imageTTFText($image, $this->fontSize, 0, $pointWidth, $pointHeight + $this->fontSize + $this->sizePoints, $pointsColor, $this->pathToFont, $i);
         // в легенду
         imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2 * ($i + 1), $legendColor, $this->pathToFont, "{$i} - " . $v->getTitle());
         $i++;
     }
     ob_start();
     imagePng($image);
     $str = ob_get_clean();
     return $str;
 }
Ejemplo n.º 15
0
    /**
     * 	Функция генерирует и выводит хидер PNG и изображение с кодом подтверждения (код берется из массива полей)
     * 	Возвращает результат выполнения imagePNG
     * 	@return	bool
     */
    function confirmImage() {

        $width = ajaxform::$captcha[width];
        $height = ajaxform::$captcha[height];

        $multi = 4;
        $xwidth = $width * $multi;
        $xheight = $height * $multi;

        $code = $this->fields[confirm][value];

        $im = imageCreateTrueColor($xwidth, $xheight);
        $w = imageColorAllocate($im, 255, 255, 255);
        $b = imageColorAllocate($im, 000, 000, 000);
        $g = imageColorAllocate($im, 100, 100, 100);
        imageFill($im, 1, 1, $w);
        $w = imageColorTransparent($im, $w);

        $r = mt_rand(0, $xheight);
        for ($x = 0; $x < $xwidth + $xheight; $x += 4 * $multi) {

            for ($i = 0; $i < $multi; $i++)
                imageLine($im, $x + $i, 0, $x + $i - $xheight, $xheight + $r, $g);
        }

        $arr = preg_split('//', $code, -1, PREG_SPLIT_NO_EMPTY);
        for ($i = 0; $i < count($arr); $i++) {

            $x = ($xwidth * 0.04) + (floor(($xwidth * 0.97) * 0.167)) * $i; // разрядка
            $y = ($xheight * 0.8);
            $s = ($xheight * 0.5) * (96 / 72); // 96 — res
            $a = mt_rand(-20, 20);

            imageTTFText($im, $s, $a, $x, $y, $b, $_SERVER[DOCUMENT_ROOT] . "/lib/core/classes/form_ajax/consolas.ttf", $arr[$i]); //
        }

        $temp = imageCreateTrueColor($xwidth, $xheight);
        $w = imageColorAllocate($temp, 255, 255, 255);
        imageFill($temp, 1, 1, $w);
        $w = imageColorTransparent($temp, $w);

        $phase = rand(-M_PI, M_PI);
        $frq = 2 * M_PI / $xheight;
        $amp = $xwidth * 0.02;

        for ($y = 0; $y < $xheight; $y++) {

            $dstx = $amp + sin($y * $frq + $phase) * $amp;

            imagecopy($temp, $im, $dstx, $y, 0, $y, $xwidth, 1);
            //imagesetpixel($im, $dstx, $y, $b);
        }

        $res = imageCreateTrueColor($width, $height);
        $w = imageColorAllocate($res, 255, 255, 255);
        imageFill($res, 1, 1, $w);
        $w = imageColorTransparent($res, $w);

        imageCopyResampled($res, $temp, 0, 0, 0, 0, $width, $height, $xwidth, $xheight);

        imageTrueColorToPalette($res, true, 256);

        header("CONTENT-TYPE: IMAGE/PNG");
        return imagePNG($res);
    }
Ejemplo n.º 16
0
//$targetPath="".WEB_PATH."";
//var $font = '/home/www/htdocs/capcha/monofont.ttf'; //╡├╟и╩═║ path р═з┴╥у╩ш╣╨д├╤║
$_SERVER['DOCUMENT_ROOT'] = dirname(dirname(__FILE__));
$targetPath = $_SERVER['DOCUMENT_ROOT'];
function generateCode($characters)
{
    $possible = '╝╗═╖┴┐╦б┤╩╟з╛├╣┬║┼└╢д╡ивк';
    //		$possible = _CAPTCHA_RAN;
    $code = '';
    $i = 0;
    while ($i < $characters) {
        $code .= substr($possible, mt_rand(0, strlen($possible) - 1), 1);
        $i++;
    }
    return $code;
}
$font = $targetPath . "/capcha/font/angsab.ttf";
$code = generateCode($_GET['characters']);
$im = imagecreate($_GET['width'], $_GET['height']);
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
$new_string = tis620_to_utf8($code);
imagefill($im, 0, 0, $black);
imageTTFText($im, 20, 0, 6, 18, $white, $font, $new_string);
if (ISO == 'utf-8') {
    $_SESSION["security_code"] = $new_string;
} else {
    $_SESSION["security_code"] = utf8_to_tis620($new_string);
}
imagepng($im);
imagedestroy($im);
Ejemplo n.º 17
0
//$d2 = 2;
//$d3 = 0;
$d4 = abs(($d1 + $d2 - $d3 + 10) * ($d1 / $d2 + $d3)) * date('j') * date('n') % 10;
$text = $d1 . $d2 . $d3 . $d4;
//$L = new C3DLib(-15,-650);
//$L = new C3DLib(0,-100);
//$L->mAddTransform('Turn', 'X', -85);
//$L->mAddTransform('Turn', 'X', -180);
//$L->mAddTransform('Turn', 'Z', -10);
//$L->mAddTransform('Turn', 'Y', 7);
$it = imageCreate($imgW, $imgH);
$itBg = imageColorAllocate($it, 128, 128, 128);
$itFg = imageColorAllocate($it, 0, 0, 0);
//	imageTTFText($it, $imgH*0.52, 0, 0,$imgH*0.825, $itFg, 'img/cambriab.ttf', $text);
//	imageTTFText($it, $imgH*0.52, 0, 0,$imgH*0.825, $itFg, 'img/impact.ttf', $text);
imageTTFText($it, $imgH * 0.6, 0, $imgW * 0.1, $imgH * 0.9, $itFg, $_SERVER['DOCUMENT_ROOT'] . '/mail/captcha/digifaw.ttf', $text);
$im = imageCreate($imgW, $imgH);
$clrBgR = $clrBg >> 16 & 0xff;
$clrBgG = $clrBg >> 8 & 0xff;
$clrBgB = $clrBg & 0xff;
$clrFgR = $clrFg >> 16 & 0xff;
$clrFgG = $clrFg >> 8 & 0xff;
$clrFgB = $clrFg & 0xff;
$imBg = imageColorAllocate($im, $clrBgR, $clrBgG, $clrBgB);
$imFg = imageColorAllocate($im, $clrFgR, $clrFgG, $clrFgB);
$imBdr = imageColorAllocate($it, 0, 0, 0);
if (1) {
    //	$c = array();
    $v = round($bgVariance / 2);
    for ($i = 0; $i < $bgVariance; $i++) {
        $r = mt_rand(-$v, $v);
Ejemplo n.º 18
0
//imagefill($dst, 0, 0, $white);
imagefilledrectangle($dst, 10, 10, 790, 590, $light_blue);
// Font size
$size = "20";
$weathersize = "10";
// Draw the text 'PHP Manual' using font size 13
//imagefttext($dst, 13, 0, 20, 400, $red, $font, 'PHP Manual');
//imagestring($dst, 200, 20, 410, 'Hello world!', $red);
// Add the text to the canvas
// Write the string at the top left
//imagecopymerge( $dst, $src1, 446, 10, 0, 0, 344, 320, 30 );
//imagecopymerge( $dst, $src2, 10, 340, 0, 0, 780, 250, 30 );
imagecopyresampled($dst, $src, 10, 10, 0, 0, 426, 320, 640, 480);
// weather
imagecopymerge($dst, $src3, 456, 200, 0, 0, 40, 40, 100);
imageTTFText($dst, $weathersize, 0, 456, 255, $white, $font, $text2);
imageTTFText($dst, $weathersize, 0, 456, 270, $white, $font, $text3);
imageTTFText($dst, $size, 0, 20, 380, $white, $font, $text);
// schatten
imageTTFText($dst, $size, 0, 23, 383, $black, $font, $text);
//imagestring($dst, $size, round(($img_w/2)-((strlen($text)*
//imagefontwidth($font_size))/2), 1), round(($img_h/2)-(imagefontheight($font_size)/2)),
//$text, $white);
//imagestring($dst, $size, round(($img_w/2)-((strlen($text)*imagefontwidth($size))/2), 1), 420, $text, $white);
header('Content-type: image/jpeg');
imagejpeg($dst);
imagedestroy($src);
imagedestroy($src1);
imagedestroy($src2);
imagedestroy($src3);
imagedestroy($dst);
Ejemplo n.º 19
0
    die("FEHLER: Datei {$xml_filename} nicht gefunden.");
}
while ($xml_data = fread($parse_handle, 4096)) {
    if (!xml_parse_into_struct($xml_parser_handle, $xml_data, $werte, $index)) {
        die(sprintf('Newsticker XML error: %s at line %d', xml_error_string(xml_get_error_code($xml_parser_handle)), xml_get_current_line_number($xml_parser_handle)));
    }
}
xml_parser_free($xml_parser_handle);
// Aktuelles News Koordinaten
$newsx = 20;
$newsy = 380;
$stepy = 23;
if ($werte[$index["TITLE"][0]]["value"] != "") {
    $news = $werte[$index["TITLE"][0]]["value"] . " vom ";
    $newsdate = $werte[$index["LASTBUILDDATE"][0]]["value"];
    imageTTFText($dst, $size, 0, $newsx, $newsy, $black, $font, $news . $newsdate);
    $zaehler = 2;
    while ($zaehler <= 7) {
        $news = $werte[$index["TITLE"][$zaehler]]["value"];
        imageTTFText($dst, $size, 0, $newsx, $zaehler * $stepy + $newsy, $black, $font, $news);
        $zaehler = $zaehler + 1;
    }
    imagecopymerge($dst, $src2, 575, 565, 0, 0, 215, 25, 100);
} else {
    imageTTFText($dst, $size + 5, 0, $newsx, $zaehler * $stepy + $newsy + 10, $black, $font, "Leider keine News :-(");
}
header('Content-type: image/jpeg');
imagejpeg($dst);
imagedestroy($src);
imagedestroy($src2);
imagedestroy($dst);
Ejemplo n.º 20
0
 /**
  * Add water mark text to an image.
  * 
  * @param string $file Image file name
  * @param string $text Text to be added as water mark
  * @param int $maxWidth Maximum width of the processed image
  * @param int $maxHeight Maximum height of the processed image
  * @param string $rename New file name for the processed image file to be saved.
  * @return bool|string Returns the generated image file name. Return false if failed.
  */
 public function waterMark($file, $text, $maxWidth, $maxHeight, $rename = '')
 {
     $file = $this->uploadPath . $file;
     $imginfo = $this->getInfo($file);
     if ($rename == '') {
         $newName = substr($imginfo['name'], 0, strrpos($imginfo['name'], '.')) . $this->waterSuffix . '.' . $this->generatedType;
     } else {
         $newName = $rename . '.' . $this->generatedType;
     }
     //create image object based on the image file type, gif, jpeg or png
     $this->createImageObject($img, $imginfo['type'], $file);
     if (!$img) {
         return false;
     }
     $width = $maxWidth > $imageInfo['width'] ? $imageInfo['width'] : $maxWidth;
     $height = $maxHeight > $imageInfo['height'] ? $imageInfo['height'] : $maxHeight;
     $oriW = $imageInfo['width'];
     $oriH = $imageInfo['height'];
     if ($oriW * $width > $oriH * $height) {
         $height = round($oriH * $width / $oriW);
     } else {
         $width = round($oriW * $height / $oriH);
     }
     if (function_exists('imagecreatetruecolor')) {
         $new = imagecreatetruecolor($width, $height);
         imagecopyresampled($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo['width'], $imageInfo['height']);
     } else {
         $new = imagecreate($width, $height);
         imagecopyresampled($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo['width'], $imageInfo['height']);
     }
     $white = imagecolorallocate($new, 255, 255, 255);
     $black = imagecolorallocate($new, 0, 0, 0);
     $alpha = imagecolorallocatealpha($new, 230, 230, 230, 40);
     imagefilledrectangle($new, 0, $height - 26, $width, $height, $alpha);
     imagefilledrectangle($new, 13, $height - 20, 15, $height - 7, $black);
     imageTTFText($new, 4.9, 0, 20, $height - 14, $black, $this->ttfFont, $text[0]);
     imageTTFText($new, 4.9, 0, 20, $height - 6, $black, $this->ttfFont, $text[1]);
     if ($this->saveFile) {
         if (file_exists($this->processPath . $newName)) {
             unlink($this->processPath . $newName);
         }
         $this->generateImage($newImg, $this->processPath . $newName);
         imagedestroy($new);
         imagedestroy($img);
         return $this->processPath . $newName;
     } else {
         $this->generateImage($newImg);
         imagedestroy($new);
         imagedestroy($img);
     }
     return true;
 }
 /**
  * @param $string
  * @param $stringColor
  */
 protected function drawString($string, $stringColor)
 {
     $string = substr($string, 0, $this->chars);
     // Draw the first few chars of the name
     imageTTFText($this->avatar, $this->fontSize, 0, 4, $this->height - $this->fontSize / 2, $stringColor, $this->fontFace, $string);
 }
Ejemplo n.º 22
0
function writeText($image, $fontsize, $xpos, $ypos, $color, $font, $text, $align, $shadow_color)
{
    // Get the font
    $font = getFont($font);
    // Get the color
    $color = setColor($image, $color);
    // Convert text for display
    $text = utf8_to_nce($text);
    // Correct alignment
    if ($align != 'left') {
        $xpos = textAlignment($font, $fontsize, $text, $xpos, $align);
    }
    // Create the pseudo-shadow
    if (!empty($shadow_color)) {
        shadowText($image, $fontsize, $xpos, $ypos, $font, $text, $shadow_color);
    }
    // Write the text
    @imageTTFText($image, $fontsize, 0, $xpos, $ypos, $color, $font, $text) or debugMode(__LINE__, $php_errormsg);
}
 public function generate($name, $colorScheme, $backgroundStyle)
 {
     list($bgColor1, $bgColor2, $textColor) = self::$colorSchemes[$colorScheme];
     $this->avatar = imageCreateTrueColor($this->width, $this->height);
     imageFill($this->avatar, 0, 0, $bgColor1);
     // Draw some random chars into the background. Unlike the other GD drawing functions
     // (imageFilledArc, imageFilledPolygon etc.) imageTTFText is anti-aliased.
     $sizeFactor = $this->width / 40;
     switch ($backgroundStyle) {
         case 0:
             imageTTFText($this->avatar, 190 * $sizeFactor, 10, 0, 35 * $sizeFactor, $bgColor2, $this->fontFace, 'O');
             break;
         case 1:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, 'o');
             break;
         case 2:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 30 * $sizeFactor, $bgColor2, $this->fontFace, '>');
             break;
         case 3:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, '//');
             break;
     }
     // Draw the first few chars of the name
     imageTTFText($this->avatar, $this->fontSize, 0, 4, $this->height - $this->fontSize / 2, $textColor, $this->fontFace, mb_substr($name, 0, $this->chars));
     // Copy the overlay on top
     if ($this->overlay) {
         imageCopy($this->avatar, $this->overlay, 0, 0, 0, 0, imageSX($this->overlay), imageSY($this->overlay));
     }
 }