Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
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);
Ejemplo n.º 3
0
 /**
  * Function: drawString
  */
 function drawFixedText($string, $x, $y, $w, $h, $style)
 {
     $lines = explode("\n", $string);
     $lineCount = sizeof($lines);
     if ($lineCount > 0) {
         // Gets the orientation and alignment
         $horizontal = mxUtils::getValue($style, mxConstants::$STYLE_HORIZONTAL, true);
         $align = mxUtils::getValue($style, mxConstants::$STYLE_ALIGN, mxConstants::$ALIGN_CENTER);
         if ($align == mxConstants::$ALIGN_LEFT) {
             if ($horizontal) {
                 $x += mxConstants::$LABEL_INSET;
             } else {
                 $y -= mxConstants::$LABEL_INSET;
             }
         } else {
             if ($align == mxConstants::$ALIGN_RIGHT) {
                 if ($horizontal) {
                     $x -= mxConstants::$LABEL_INSET;
                 } else {
                     $y += mxConstants::$LABEL_INSET;
                 }
             }
         }
         if ($horizontal) {
             $y += 2 * mxConstants::$LABEL_INSET;
         } else {
             $y += $h;
             $x += 2 * mxConstants::$LABEL_INSET;
         }
         // Gets the font
         $fontSize = mxUtils::getValue($style, mxConstants::$STYLE_FONTSIZE, mxConstants::$DEFAULT_FONTSIZE) * $this->scale;
         $fontFamily = mxUtils::getValue($style, mxConstants::$STYLE_FONTFAMILY, mxConstants::$DEFAULT_FONTFAMILY);
         $font = $this->getFixedFontSize($fontSize, $fontFamily);
         // Gets the color
         $fontColor = mxUtils::getValue($style, mxConstants::$STYLE_FONTCOLOR);
         $color = $this->getColor($fontColor, "black");
         $dx = imageFontWidth($font);
         $dy = (($horizontal ? $h : $w) - 2 * mxConstants::$LABEL_INSET) / $lineCount;
         // Draws the text line by line
         for ($i = 0; $i < $lineCount; $i++) {
             $left = $x;
             $top = $y;
             $lineWidth = strlen($lines[$i]) * $dx;
             if ($align == mxConstants::$ALIGN_CENTER) {
                 if ($horizontal) {
                     $left += ($w - $lineWidth) / 2;
                 } else {
                     $top -= ($h - $lineWidth) / 2;
                 }
             } else {
                 if ($align == mxConstants::$ALIGN_RIGHT) {
                     if ($horizontal) {
                         $left += $w - $lineWidth;
                     } else {
                         $top -= $h - $lineWidth;
                     }
                 }
             }
             $this->drawFixedTextLine($lines[$i], $font, $left, $top, $color, $horizontal);
             if ($horizontal) {
                 $y += $dy;
             } else {
                 $x += $dy;
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
} elseif (strlen($maxClicks) > 1) {
    $maxClicks = ceil($maxClicks / pow(10, strlen($maxClicks) - 1)) * pow(10, strlen($maxClicks) - 1);
} else {
    $maxClicks = 10;
}
// Use the same scale
if (defined('LIB_GRAPH_SAME_SCALE')) {
    if ($maxViews > $maxClicks) {
        $maxClicks = $maxViews;
    } else {
        $maxViews = $maxClicks;
    }
}
// Margins
$leftMargin = strlen($maxViews) * imageFontWidth(2);
$rightMargin = strlen($maxClicks) * imageFontWidth(2);
$margin = $leftMargin + $rightMargin;
// Headers
$text["value1"] .= ": " . $totalViews;
$text["value2"] .= ": " . $totalClicks;
// Dimensions
if (!isset($height)) {
    $height = 180;
}
if (!isset($width)) {
    $width = max($margin + 20 + 12 * $items_count, $margin + 50 + imageFontwidth(2) * (strlen($text["value1"]) + strlen($text["value2"])));
}
$im = imagecreate($width, $height);
$bgcolor = ImageColorAllocate($im, $bgcolors[0], $bgcolors[1], $bgcolors[2]);
$linecolor = ImageColorAllocate($im, $linecolors[0], $linecolors[1], $linecolors[2]);
$graycolor = ImageColorAllocate($im, $RGB['lgray'][0], $RGB['lgray'][1], $RGB['lgray'][2]);
Ejemplo n.º 6
0
$user = substr($_GET['player'], 0, 30);
$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
Ejemplo n.º 7
0
<?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);
Ejemplo n.º 8
0
 imageSaveAlpha($teamoverlay, true);
 imageAlphaBlending($teamoverlay, true);
 $transparentColor = imagecolorallocatealpha($teamoverlay, 200, 200, 200, 127);
 imagefill($teamoverlay, 0, 0, $transparentColor);
 //set up colors
 $white = imagecolorallocate($teamoverlay, 255, 255, 255);
 $negwhite = 0 - $white;
 $black = imagecolorallocate($teamoverlay, 0, 0, 0);
 $negblack = 0 - $black;
 $year = date('Y');
 $team = getTeamDetails($teamnumber, $year);
 $teamstring = "Team {$teamnumber}";
 if ($team["nickname"] != "") {
     $teamstring = $teamstring . " - {$team["nickname"]}";
 }
 $location_offset = imageFontWidth(3) * strlen($teamstring) + 15;
 $yearWLT = "";
 //TODO: Reimplement WLT
 imageStringoutline($teamoverlay, 3, 8, 5, $white, $black, $teamstring, 1);
 imagettftextoutline($teamoverlay, 6, 0, $location_offset, 16, $negwhite, $negblack, 'slkscr.ttf', $team["location"], 1);
 if (count($team["events"]) > 4) {
     $event_text_offset = 27;
 } else {
     $event_text_offset = 30;
     //18 for imageStringOutline, 30 for TTF
 }
 if ($team["events"]) {
     usort($events = $team["events"], "eventSort");
     foreach ($events as $event) {
         //if ($eventWLT != "(0-0-0)") {
         //	$highestmatch = getHighestMatch($eventid, "string", $teamnumber);
Ejemplo n.º 9
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();
 }
Ejemplo n.º 10
0
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;
    }
}
Ejemplo n.º 11
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);
Ejemplo n.º 12
0
//干扰像素
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);