Exemple #1
0
 public function createImage($text = '', $fontSize = 5)
 {
     // GD's built-in fonts are numbered from 1 - 5
     $font_size = $fontSize;
     // Calculate the appropriate image size
     $image_height = intval(imageFontHeight($font_size) * 2);
     $image_width = intval(strlen($text) * imageFontWidth($font_size) * 1.3);
     // Create the image
     $image = imageCreate($image_width, $image_height);
     // Create the colors to use in the image
     // gray background
     $back_color = imageColorAllocate($image, 216, 216, 216);
     // blue text
     $text_color = imageColorAllocate($image, 0, 0, 255);
     // black border
     $rect_color = imageColorAllocate($image, 0, 0, 0);
     // Figure out where to draw the text
     // (Centered horizontally and vertically
     $x = ($image_width - imageFontWidth($font_size) * strlen($text)) / 2;
     $y = ($image_height - imageFontHeight($font_size)) / 2;
     // Draw the text
     imageString($image, $font_size, $x, $y, $text, $text_color);
     // Draw a black border
     imageRectangle($image, 0, 0, imageSX($image) - 1, imageSY($image) - 1, $rect_color);
     // Send the image to the browser
     header('Content-Type: image/png');
     imagePNG($image);
     imageDestroy($image);
 }
if (intval($z) > 13) {
    $fac = pow(2, $z - 13);
    $x = (int) ($x / $fac);
    $y = (int) ($y / $fac);
    $file = $base . "packed/" . $x . "/" . $y . ".pack";
} else {
    $file = $base . $z . "/" . $x . "/" . $y . ".png";
}
$string = date("Y-m-d H:i:s", filemtime($file));
$iwidth = 256;
$iheight = 128;
// create empty image
$img = ImageCreateTrueColor($iwidth, $iheight);
$transparentCol = imagecolorallocate($img, 255, 255, 0);
imagefilledrectangle($img, 0, 0, $iwidth, $iheight, $transparentCol);
imagecolortransparent($img, $transparentCol);
// write text
$font = 16;
$width = imageFontWidth($font) * strlen($string);
$height = imageFontHeight($font);
$x = imagesx($img) - $width;
$y = imagesy($img) - 2 * $height;
$backgroundColor = imagecolorallocate($img, 255, 255, 255);
$textColor = imagecolorallocate($img, 0, 0, 0);
imageString($img, $font, $x - 1, $y - 1, $string, $backgroundColor);
imageString($img, $font, $x - 1, $y + 1, $string, $backgroundColor);
imageString($img, $font, $x + 1, $y + 1, $string, $backgroundColor);
imageString($img, $font, $x + 1, $y - 1, $string, $backgroundColor);
imageString($img, $font, $x, $y, $string, $textColor);
//imageString ($img, $font, $x-50, $y-20, $file, $textColor);
ImagePng($img);
 /**
  * Appends information about the source image to the thumbnail.
  * 
  * @param	string		$thumbnail
  * @return	string
  */
 protected function appendSourceInfo($thumbnail)
 {
     if (!function_exists('imageCreateFromString') || !function_exists('imageCreateTrueColor')) {
         return $thumbnail;
     }
     $imageSrc = imageCreateFromString($thumbnail);
     // get image size
     $width = imageSX($imageSrc);
     $height = imageSY($imageSrc);
     // increase height
     $heightDst = $height + self::$sourceInfoLineHeight * 2;
     // create new image
     $imageDst = imageCreateTrueColor($width, $heightDst);
     imageAlphaBlending($imageDst, false);
     // set background color
     $background = imageColorAllocate($imageDst, 102, 102, 102);
     imageFill($imageDst, 0, 0, $background);
     // copy image
     imageCopy($imageDst, $imageSrc, 0, 0, 0, 0, $width, $height);
     imageSaveAlpha($imageDst, true);
     // get font size
     $font = 2;
     $fontWidth = imageFontWidth($font);
     $fontHeight = imageFontHeight($font);
     $fontColor = imageColorAllocate($imageDst, 255, 255, 255);
     // write source info
     $line1 = $this->sourceName;
     // imageString supports only ISO-8859-1 encoded strings
     if (CHARSET != 'ISO-8859-1') {
         $line1 = StringUtil::convertEncoding(CHARSET, 'ISO-8859-1', $line1);
     }
     // truncate text if necessary
     $maxChars = floor($width / $fontWidth);
     if (strlen($line1) > $maxChars) {
         $line1 = $this->truncateSourceName($line1, $maxChars);
     }
     $line2 = $this->sourceWidth . 'x' . $this->sourceHeight . ' ' . FileUtil::formatFilesize($this->sourceSize);
     // write line 1
     // calculate text position
     $textX = 0;
     $textY = 0;
     if ($fontHeight < self::$sourceInfoLineHeight) {
         $textY = intval(round((self::$sourceInfoLineHeight - $fontHeight) / 2));
     }
     if (strlen($line1) * $fontWidth < $width) {
         $textX = intval(round(($width - strlen($line1) * $fontWidth) / 2));
     }
     imageString($imageDst, $font, $textX, $height + $textY, $line1, $fontColor);
     // write line 2
     // calculate text position
     $textX = 0;
     $textY = 0;
     if ($fontHeight < self::$sourceInfoLineHeight) {
         $textY = self::$sourceInfoLineHeight + intval(round((self::$sourceInfoLineHeight - $fontHeight) / 2));
     }
     if (strlen($line2) * $fontWidth < $width) {
         $textX = intval(round(($width - strlen($line2) * $fontWidth) / 2));
     }
     imageString($imageDst, $font, $textX, $height + $textY, $line2, $fontColor);
     // output image
     ob_start();
     if ($this->imageType == 1 && function_exists('imageGIF')) {
         @imageGIF($imageDst);
         $this->mimeType = 'image/gif';
     } else {
         if (($this->imageType == 1 || $this->imageType == 3) && function_exists('imagePNG')) {
             @imagePNG($imageDst);
             $this->mimeType = 'image/png';
         } else {
             if (function_exists('imageJPEG')) {
                 @imageJPEG($imageDst, null, 90);
                 $this->mimeType = 'image/jpeg';
             } else {
                 return false;
             }
         }
     }
     @imageDestroy($imageDst);
     $thumbnail = ob_get_contents();
     ob_end_clean();
     return $thumbnail;
 }
Exemple #4
0
$stringx = $stringy = -1;
$file = file($irpg_db);
unset($file[0]);
foreach ($file as $line) {
    list($username, , , , , , , , , , $x, $y) = explode("\t", trim($line));
    if ($username == $user) {
        $stringx = $x;
        $stringy = $y;
        break;
    }
}
if ($stringx == $stringy && $stringx == -1) {
    imageString($map, 5, 200, 245, "NO SUCH USER", imagecolorallocate($map, 255, 0, 0));
} else {
    $width = imageFontWidth(5);
    $height = imageFontHeight(5);
    if ($x + (strlen($user) + 1) * $width > 500) {
        $stringx = $x - (strlen($user) + 1) * $width - 12;
    }
    if ($y + $height > 500) {
        $stringy = $y - $height / 2 - 2;
    }
    $magenta = imageColorAllocate($map, 255, 0, 255);
    imageColorTransparent($map, $magenta);
    $brown = imagecolorallocate($map, 102, 51, 0);
    $parchment = imagecolorallocate($map, 255, 255, 204);
    // Avoid drawing a brown dot on a brown area
    $rgb = imageColorAt($map, $x, $y);
    if ($rgb > 0) {
        // $rgb is 0 on our parchment-colored areas
        $temp = $brown;
<?php

// GD's built-in fonts are numbered from 1 - 5
$font_size = 5;
// Calculate the appropriate image size
$image_height = intval(imageFontHeight($font_size) * 2);
$image_width = intval(strlen($_GET['text']) * imageFontWidth($font_size) * 1.3);
// Create the image
$image = imageCreate($image_width, $image_height);
// Create the colors to use in the image
// gray background
$back_color = imageColorAllocate($image, 216, 216, 216);
// blue text
$text_color = imageColorAllocate($image, 0, 0, 255);
// black border
$rect_color = imageColorAllocate($image, 0, 0, 0);
// Figure out where to draw the text
// (Centered horizontally and vertically
$x = ($image_width - imageFontWidth($font_size) * strlen($_GET['text'])) / 2;
$y = ($image_height - imageFontHeight($font_size)) / 2;
// Draw the text
imageString($image, $font_size, $x, $y, $_GET['text'], $text_color);
// Draw a black border
imageRectangle($image, 0, 0, imageSX($image) - 1, imageSY($image) - 1, $rect_color);
// Send the image to the browser
header('Content-Type: image/png');
imagePNG($image);
imageDestroy($image);
Exemple #6
0
 /**
  * Function: getSizeForString
  * 
  * Returns an <mxRectangle> with the size (width and height in pixels) of
  * the given string. The string may contain HTML markup. Newlines should be
  * converted to <br> before calling this method.
  * 
  * Parameters:
  * 
  * text - String whose size should be returned.
  * fontSize - Integer that specifies the font size in pixels. Default is
  * <mxConstants.DEFAULT_FONTSIZE>.
  * fontFamily - String that specifies the name of the font famil.y Default
  * is <mxConstants.DEFAULT_FONTFAMILY>.
  * 
  */
 static function getSizeForString($text, $fontSize = 0, $fontFamily = null)
 {
     if (is_string($text) && strlen($text) > 0) {
         if ($fontSize == 0) {
             $fontSize = mxConstants::$DEFAULT_FONTSIZE;
         }
         if ($fontFamily == null) {
             $fontFamily = mxConstants::$DEFAULT_FONTFAMILY;
         }
         $lines = explode("\n", $text);
         $lineCount = sizeof($lines);
         if (mxConstants::$TTF_ENABLED && function_exists("imagettfbbox")) {
             $bbox = imagettfbbox($fontSize * mxConstants::$TTF_SIZEFACTOR, 0, $fontFamily, $text);
             $textWidth = $bbox[2] - $bbox[0];
             $textHeight = ($fontSize + mxConstants::$DEFAULT_LINESPACING) * $lineCount;
             return new mxRectangle(0, 0, $textWidth, $textHeight);
         } else {
             if (function_exists("imageFontHeight") && function_exists("imageFontWidth")) {
                 $font = mxUtils::getFixedFontSize($fontSize, $fontFamily);
                 $textHeight = (imageFontHeight($font) + mxConstants::$DEFAULT_LINESPACING) * $lineCount;
                 $charWidth = imageFontWidth($font);
                 $textWidth = 0;
                 for ($i = 0; $i < sizeof($lines); $i++) {
                     $textWidth = max($textWidth, $charWidth * strlen($lines[$i]));
                 }
                 return new mxRectangle(0, 0, $textWidth, $textHeight);
             }
         }
     }
     return new mxRectangle();
 }
function addCoordinates($im, $direction)
{
    if (!isCoordinatesEnabled()) {
        return;
    }
    $decorationWidth = getDecorationWidth();
    $squareSize = getSquareSize();
    $font = getCoordinateFont();
    $x_left_numbers = ($decorationWidth - imageFontWidth($font)) / 2;
    $x_right_numbers = $x_left_numbers + 8 * $squareSize + $decorationWidth;
    $y1 = $decorationWidth + ($squareSize - imageFontHeight($font)) / 2;
    if ($direction == 'normal') {
        $deltaY = $squareSize;
    } else {
        $y1 = $y1 + 7 * $squareSize;
        $deltaY = -$squareSize;
    }
    $black = imageColorAllocate($im, 0, 0, 0);
    $y = $y1;
    for ($k = 8; $k >= 1; $k--) {
        imageString($im, $font, $x_left_numbers, $y, $k, $black);
        imageString($im, $font, $x_right_numbers, $y, $k, $black);
        $y += $deltaY;
    }
    $file = substr($files, $k - 1, 1);
    $x1 = $decorationWidth + ($squareSize - imageFontWidth($font)) / 2;
    $y_top_letters = ($decorationWidth - imageFontHeight($font)) / 2;
    $y_bottom_letters = $y_top_letters + 8 * $squareSize + $decorationWidth;
    if ($direction == 'normal') {
        $deltaX = $squareSize;
    } else {
        $x1 = $x1 + 7 * $squareSize;
        $deltaX = -$squareSize;
    }
    $files = 'abcdefgh';
    $x = $x1;
    for ($k = 0; $k < 8; $k++) {
        $file = substr($files, $k, 1);
        imageString($im, $font, $x, $y_top_letters, $file, $black);
        imageString($im, $font, $x, $y_bottom_letters, $file, $black);
        $x += $deltaX;
    }
}
Exemple #8
0
<?php

// GD's built-in fonts are numbered from 1 - 5
$font = 3;
// Calculate the appropriate image size
$image_height = intval(imageFontHeight($font) * 2);
$image_width = intval(strlen($_GET['button']) * imageFontWidth($font) * 1.3);
// Create the image
$image = imageCreate($image_width, $image_height);
// Create the colors to use in the image
// gray background
$back_color = imageColorAllocate($image, 216, 216, 216);
// blue text
$text_color = imageColorAllocate($image, 0, 0, 255);
// black border
$rect_color = imageColorAllocate($image, 0, 0, 0);
// Figure out where to draw the text
// (Centered horizontally and vertically
$x = ($image_width - imageFontWidth($font) * strlen($_GET['button'])) / 2;
$y = ($image_height - imageFontHeight($font)) / 2;
// Draw the text
imageString($image, $font, $x, $y, $_GET['button'], $text_color);
// Draw a black border
imageRectangle($image, 0, 0, imageSX($image) - 1, imageSY($image) - 1, $rect_color);
// Send the image to the browser
header('Content-Type: image/png');
imagePNG($image);
imageDestroy($image);
//干扰像素
for ($i = 0; $i <= 300; ++$i) {
    $color = imageColorAllocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    imageSetPixel($img, mt_rand(0, $img_w), mt_rand(0, $img_h), $color);
}
for ($i = 0; $i <= 10; ++$i) {
    //设置直线颜色
    $color = imageColorAllocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    //在$img图像上随机画一条直线
    imageline($img, mt_rand(0, $img_w), mt_rand(0, $img_h), mt_rand(0, $img_w), mt_rand(0, $img_h), $color);
}
//矩形边框
$rect_color = imageColorAllocate($img, 0x90, 0x90, 0x90);
//白
imageRectangle($img, 0, 0, $img_w - 1, $img_h - 1, $rect_color);
//----2 操作画布
//设定字符串颜色
$str_color = imageColorAllocate($img, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
//设定字符串位置
$font_w = imageFontWidth($font);
//字体宽
$font_h = imageFontHeight($font);
//字体高
$str_w = $font_w * $char_len;
//字符串宽
imageString($img, $font, ($img_w - $str_w) / 2, ($img_h - $font_h) / 2, $code, $str_color);
//----3 输出图片内容
header('Content-Type: image/png');
imagepng($img);
//----4 销毁画布
imagedestroy($img);