private function getTextSize($fontSize, $angle, $font, $text)
 {
     // *** Define box (so we can get the width)
     $box = @imageTTFBbox($fontSize, $angle, $font, $text);
     // ***  Get width of text from dimensions
     $textWidth = abs($box[4] - $box[0]);
     // ***  Get height of text from dimensions (should also be same as $fontSize)
     $textHeight = abs($box[5] - $box[1]);
     return array('height' => $textHeight, 'width' => $textWidth);
 }
function watermarkImage($SourceFile, $WaterMarkText, $DestinationFile)
{
    list($width, $height) = getimagesize($SourceFile);
    $image_p = imagecreatetruecolor($width, $height);
    $image = imagecreatefromjpeg($SourceFile);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
    $black = imagecolorallocate($image_p, 255, 255, 255);
    $font = 'lib/arial.ttf';
    $font_size = 13;
    $font_angle = 0;
    $box = @imageTTFBbox($font_size, $font_angle, $font, $WaterMarkText);
    $textwidth = abs($box[4] - $box[0]);
    $textheight = abs($box[5] - $box[1]);
    $xcord = $width - 120 - $textwidth / 2 - 2;
    $ycord = $height - 20 + $textheight / 2;
    imagettftext($image_p, $font_size, 0, $xcord, $ycord, $black, $font, $WaterMarkText);
    if ($DestinationFile != '') {
        imagejpeg($image_p, $DestinationFile, 100);
    } else {
        header('Content-Type: image/jpeg');
        imagejpeg($image_p, null, 100);
    }
    imagedestroy($image);
    imagedestroy($image_p);
}
Beispiel #3
0
 function Captcha($text, $font, $color)
 {
     $C = HexDec($color);
     $R = floor($C / pow(256, 2));
     $G = floor($C % pow(256, 2) / pow(256, 1));
     $B = floor($C % pow(256, 2) % pow(256, 1) / pow(256, 0));
     $fsize = 32;
     $bound = array();
     $bound = imageTTFBbox($fsize, 0, $font, $text);
     $this->image = imageCreateTrueColor($bound[4] + 5, abs($bound[5]) + 15);
     imageFill($this->image, 0, 0, ImageColorAllocate($this->image, 255, 255, 255));
     imagettftext($this->image, $fsize, 0, 2, abs($bound[5]) + 5, ImageColorAllocate($this->image, $R, $G, $B), $font, $text);
 }
Beispiel #4
0
function generateVerticalString($string, $id, $doc, $invert = false)
{
    $string = '     ' . iconv('UTF-8', 'macintosh', $string);
    $doc_exploded = explode(DCTL_RESERVED_INFIX, $doc);
    $db_collection = isset($doc_exploded[0]) ? $doc_exploded[0] : '';
    $dest = '';
    $dest .= DCTL_DBCTL_BASEPATH . 'coste';
    if (!is_dir($dest)) {
        mkdir($dest, CHMOD);
    }
    @chmod($dest, CHMOD);
    $dest .= SYS_PATH_SEP . $doc . '-' . $id . '.gif';
    $font = 'font/Georgia.ttf';
    $fontsize = 12;
    $bolder = false;
    $fontangle = 0;
    $rotateangle = 90;
    $x_cord = 0;
    $y_cord = $fontsize * 2;
    $box = @imageTTFBbox($fontsize, $fontangle, $font, $string);
    $g_iw = abs($box[4] - $box[0]) + $fontsize + $x_cord;
    $g_ih = $fontsize * 2.3;
    $img_dst = imagecreatetruecolor($g_iw, $g_ih);
    $fg = imagecolorallocate($img_dst, 0, 0, 0);
    $bg = imagecolorallocate($img_dst, 127, 127, 127);
    if ($invert) {
        $bg = $fg;
        $fg = imagecolorallocate($img_dst, 255, 255, 255);
    }
    imagecolortransparent($img_dst, $bg);
    imagefilledrectangle($img_dst, 0, 0, $g_iw, $g_ih, $bg);
    if ($bolder) {
        imagettftext($img_dst, $fontsize, $fontangle, $x_cord + 2, $y_cord + 2, $bg, $font, $string);
        $_x = array(1, 0, 1, 0, -1, -1, 1, 0, -1);
        $_y = array(0, -1, -1, 0, 0, -1, 1, 1, 1);
        for ($n = 0; $n <= 8; $n++) {
            imagettftext($img_dst, $fontsize, $fontangle, $x_cord + $_x[$n], $y_cord + $_y[$n], $fg, $font, $string);
        }
    } else {
        //		imagettftext($img_dst, $fontsize, $fontangle, $x_cord+1, $y_cord+1, $bg, $font, $string);
        imagettftext($img_dst, $fontsize, $fontangle, $x_cord, $y_cord, $fg, $font, $string);
    }
    // 	$icon_src = imagecreatefromgif(DCTL_IMAGES.'box_opened.gif');
    // 	imagecopy($img_dst, $icon_src, 3, 9, 0, 0, 20, 20);
    $img_dst = imagerotate($img_dst, $rotateangle, 0);
    imagegif($img_dst, $dest);
    imagedestroy($img_dst);
}
 static function renderPlaceholder($width, $height, $bg_color = false, $text_color = false, $icon_path = false, $text_string = false)
 {
     // Check size
     $width = $width > 2000 ? 2000 : $width;
     $height = $height > 2000 ? 2000 : $height;
     // Check colors
     $bg_color = !$bg_color && $bg_color != "000" && $bg_color != "000000" ? "CCCCCC" : ltrim($bg_color, "#");
     $text_color = !$text_color && $text_color != "000" && $text_color != "000000" ? "666666" : ltrim($text_color, "#");
     // Set text
     $text = $text_string;
     if ($icon_path) {
         $text = "";
     } else {
         if (!$text_string) {
             $text = $width . " X " . $height;
         }
     }
     // Create image
     $image = imagecreatetruecolor($width, $height);
     // Build rgba from hex
     $bg_color = imagecolorallocate($image, base_convert(substr($bg_color, 0, 2), 16, 10), base_convert(substr($bg_color, 2, 2), 16, 10), base_convert(substr($bg_color, 4, 2), 16, 10));
     $text_color = imagecolorallocate($image, base_convert(substr($text_color, 0, 2), 16, 10), base_convert(substr($text_color, 2, 2), 16, 10), base_convert(substr($text_color, 4, 2), 16, 10));
     // Fill image
     imagefill($image, 0, 0, $bg_color);
     /*
     		if ($icon_path) {
     $icon_size = getimagesize($icon_path);
     $icon_width = $icon_size[0];
     $icon_height = $icon_size[1];
     $icon_x = ($width - $icon_width) / 2;
     $icon_y = ($height - $icon_height) / 2;
     
     $icon = imagecreatefrompng($icon_path);
     imagesavealpha($icon, true);
     imagealphablending($icon, true);
     imagecopyresampled($image, $icon, $icon_x, $icon_y, 0, 0, $icon_width, $icon_height, $icon_width, $icon_height);
     */
     //} elseif ($text) {
     if ($text) {
         $font = ROOT_DIR . "vendor/nano_placeholder/arial.ttf";
         $fontsize = $width > $height ? $height / 15 : $width / 15;
         $textpos = imageTTFBbox($fontsize, 0, $font, $text);
         imagettftext($image, $fontsize, 0, ($width - $textpos[2]) / 2, ($height - $textpos[5]) / 2, $text_color, $font, $text);
     }
     // Serve image and die
     header("Content-Type: image/png");
     imagepng($image);
     imagedestroy($image);
     die;
 }
Beispiel #6
0
/**
 * Generate a random string, and create a CAPTCHA image out of it
 */
function create_image()
{
    // generate pronouncable pass
    $pass = genPassword(5, 6);
    $font = './captcha.ttf';
    $maxsize = 50;
    $sizeVar = 25;
    $rotate = 20;
    $bgcol = 50;
    // + 50
    $bgtextcol = 80;
    // + 50
    $textcol = 205;
    // + 50
    // remember the pass
    $_SESSION["captcha"] = $pass;
    // calculate dimentions required for pass
    $box = @imageTTFBbox($maxsize, 0, $font, $pass);
    $minwidth = abs($box[4] - $box[0]);
    $minheight = abs($box[5] - $box[1]);
    // allow spacing for rotating letters
    $width = $minwidth + 100;
    $height = $minheight + rand(5, 15);
    // give some air for the letters to breathe
    // create initial image
    $image = ImageCreatetruecolor($width, $height);
    if (function_exists('imageantialias')) {
        imageantialias($image, true);
    }
    // define background color - never the same, close to black
    $clr_black = ImageColorAllocate($image, rand($bgcol, $bgcol + 30), rand($bgcol, $bgcol + 30), rand($bgcol, $bgcol + 30));
    imagefill($image, 0, 0, $clr_black);
    // calculate starting positions for letters
    $x = rand(10, 25);
    //($width / 2) - ($minwidth / 2);
    $xinit = $x;
    $y = $minheight - abs($box[1]) + ($height - $minheight) / 2;
    // fill the background with big letters, colored a bit lightly, to vary the bg.
    $bgx = $x / 2;
    $size = rand($maxsize - 10, $maxsize);
    for ($i = 0; $i < strlen($pass); $i++) {
        // modify color a bit
        $clr_white = ImageColorAllocate($image, rand($bgtextcol, $bgtextcol + 50), rand($bgtextcol, $bgtextcol + 50), rand($bgtextcol, $bgtextcol + 50));
        $angle = rand(0 - $rotate, $rotate);
        $letter = substr($pass, $i, 1);
        imagettftext($image, $size * 2, $angle, $bgx, $y, $clr_white, $font, $letter);
        list($x1, $a, $a, $a, $x2) = @imageTTFBbox($size, $angle, $font, $letter);
        $bgx += abs($x2 - $x1);
    }
    // for each letter, decide a color, decide a rotation, put it on the image,
    //     and figure out width to place next letter correctly
    for ($i = 0; $i < strlen($pass); $i++) {
        // modify color a bit
        $clr_white = ImageColorAllocate($image, rand($textcol, $textcol + 50), rand($textcol, $textcol + 50), rand($textcol, $textcol + 50));
        $angle = rand(0 - $rotate, $rotate);
        $letter = substr($pass, $i, 1);
        $size = rand($maxsize - $sizeVar, $maxsize);
        $tempbox = @imageTTFBbox($size, $angle, $font, $letter);
        $y = abs($tempbox[5] - $tempbox[1]) + ($height - abs($tempbox[5] - $tempbox[1])) / 2;
        imagettftext($image, $size, $angle, $x, $y, $clr_white, $font, $letter);
        $x += abs($tempbox[4] - $tempbox[0]);
    }
    // figure out final width (same space at the end as there was at the beginning)
    $width = $xinit + $x;
    // throw in some lines
    $clr_white = ImageColorAllocate($image, rand(160, 200), rand(160, 200), rand(160, 200));
    imagelinethick($image, rand(0, 10), rand(0, $height / 2), rand($width - 10, $width), rand($height / 2, $height), $clr_white, rand(1, 2));
    $clr_white = ImageColorAllocate($image, rand(160, 200), rand(160, 200), rand(160, 200));
    imagelinethick($image, rand($width / 2 - 10, $width / 2), rand($height / 2, $height), rand($width / 2 + 10, $width), rand(0, $height / 2), $clr_white, rand(1, 2));
    // generate final image by cropping initial image to the proper width,
    //     which we didn't know till now.
    $finalimage = ImageCreatetruecolor($width, $height);
    if (function_exists('imageantialias')) {
        imageantialias($finalimage, true);
    }
    imagecopy($finalimage, $image, 0, 0, 0, 0, $width, $height);
    // clear some memory
    imagedestroy($image);
    // dump image
    imagepng($finalimage);
    // clear some more memory
    imagedestroy($finalimage);
}
Beispiel #7
0
/**
 * @name                    : makeImageF
 *
 * Function for create image from text with selected font. Justify text in image (0-Left, 1-Right, 2-Center).
 *
 * @param String $text     : String to convert into the Image.
 * @param String $font     : Font name of the text. Kip font file in same folder.
 * @param int    $Justify  : Justify text in image (0-Left, 1-Right, 2-Center).
 * @param int    $Leading  : Space between lines.
 * @param int    $W        : Width of the Image.
 * @param int    $H        : Hight of the Image.
 * @param int    $X        : x-coordinate of the text into the image.
 * @param int    $Y        : y-coordinate of the text into the image.
 * @param int    $fsize    : Font size of text.
 * @param array  $color    : RGB color array for text color.
 * @param array  $bgcolor  : RGB color array for background.
 *
 */
function wplan_imagettfJustifytext($text, $font = "pub/adg/Vera.ttf", $Justify = 2, $Leading = 0, $W = 0, $H = 0, $X = 0, $Y = 0, $fsize = 12, $color = array(0x0, 0x0, 0x0), $bgcolor = array(0xff, 0xff, 0xff))
{
    $angle = 0;
    $_bx = imageTTFBbox($fsize, 0, $font, $text);
    $s = split("[\n]+", $text);
    // Array of lines
    $nL = count($s);
    // Number of lines
    $W = $W == 0 ? abs($_bx[2] - $_bx[0]) : $W;
    // If Width not initialized by programmer then it will detect and assign perfect width.
    $H = $H == 0 ? abs($_bx[5] - $_bx[3]) + ($nL > 1 ? $nL * $Leading : 0) : $H;
    // If Height not initialized by programmer then it will detect and assign perfect height.
    $im = @imagecreate($W, $H) or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, $bgcolor[0], $bgcolor[1], $bgcolor[2]);
    // RGB color background.
    $text_color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
    // RGB color text.
    if ($Justify == 0) {
        //Justify Left
        imagettftext($im, $fsize, $angle, $X, $fsize, $text_color, $font, $text);
    } else {
        // Create alpha-nummeric string with all international characters - both upper- and lowercase
        $alpha = range("a", "z");
        $alpha = $alpha . strtoupper($alpha) . range(0, 9);
        // Use the string to determine the height of a line
        $_b = imageTTFBbox($fsize, 0, $font, $alpha);
        $_H = abs($_b[5] - $_b[3]);
        $__H = 0;
        for ($i = 0; $i < $nL; $i++) {
            $_b = imageTTFBbox($fsize, 0, $font, $s[$i]);
            $_W = abs($_b[2] - $_b[0]);
            //Defining the X coordinate.
            if ($Justify == 1) {
                $_X = $W - $_W;
            } else {
                $_X = abs($W / 2) - abs($_W / 2);
            }
            // Justify Center
            //Defining the Y coordinate.
            $__H += $_H;
            imagettftext($im, $fsize, $angle, $_X, $__H, $text_color, $font, $s[$i]);
            $__H += $Leading;
        }
    }
    return $im;
}
 /**
  * Generates the barcode data
  * @param  string  $string  The string to encode
  * @param  integer $width   The width of the image
  * @param  integer $height  The height of the image
  * @return data
  */
 private function _generate($string, $width = NULL, $height = NULL)
 {
     //	Prep the string
     $string = strtoupper($string);
     $string = preg_replace('/[^A-Z0-9]/', '', $string);
     // --------------------------------------------------------------------------
     if (empty($string)) {
         $this->_set_error('String cannot be empty');
         return FALSE;
     }
     // --------------------------------------------------------------------------
     //	Create an oversized image first. We're going to generate the barcode with
     //	the text centered then crop it to fit into an image of the requested size.
     $_width = 2000;
     $_height = 60;
     $_img = imagecreate($_width, $_height);
     //	Define the colours
     $background = imagecolorallocate($_img, 255, 255, 255);
     $black = imagecolorallocate($_img, 0, 0, 0);
     // --------------------------------------------------------------------------
     //	Write the barcode text, centered
     $_fontsize = 36;
     $_font = $this->_font_barcode;
     $_box = @imageTTFBbox($_fontsize, 0, $_font, $string);
     $_textw = abs($_box[4] - $_box[0]);
     $_texth = abs($_box[5] - $_box[1]);
     $_xcord = $_width / 2 - $_textw / 2 - 2;
     $_ycord = $_texth;
     imagettftext($_img, $_fontsize, 0, $_xcord, $_ycord, $black, $_font, $string);
     $_barcode_height = $_texth;
     $_barcode_width = $_textw;
     $_barcode_xcord = $_xcord;
     // --------------------------------------------------------------------------
     //	Write the number text, also centered
     $_fontsize = 14;
     $_font = $this->_font_plain;
     $_box = @imageTTFBbox($_fontsize, 0, $_font, $string);
     $_textw = abs($_box[4] - $_box[0]);
     $_texth = abs($_box[5] - $_box[1]);
     $_xcord = $_width / 2 - $_textw / 2 - 2;
     $_ycord = $_barcode_height + $_texth;
     //	If the string contains a J or a Q then the positioning of the string is
     //	skewed, adjust accordingly.
     if (strpos($string, 'J') == FALSE && strpos($string, 'Q') == FALSE) {
         $_ycord += 5;
     }
     imagettftext($_img, $_fontsize, 0, $_xcord, $_ycord, $black, $_font, $string);
     $_text_height = $_texth;
     $_text_width = $_textw;
     $_text_xcord = $_xcord;
     // --------------------------------------------------------------------------
     //	Crop image to fit barcode; it seems there's a PHP bug however - image crop
     //	creates black lines when cropping: https://bugs.php.net/bug.php?id=67447
     $_options = array();
     $_options['height'] = $_height;
     $_options['width'] = max($_barcode_width, $_text_width);
     $_options['y'] = 0;
     $_options['x'] = min($_barcode_xcord, $_text_xcord);
     $_img_cropped = imagecrop($_img, $_options);
     imagedestroy($_img);
     // --------------------------------------------------------------------------
     //	If a user defined width or height has been supplied then resize to those
     //	dimensions.
     if (!is_null($width) || !is_null($height)) {
         $width = is_null($width) ? $_options['width'] : $width;
         $height = is_null($height) ? $_options['height'] : $height;
         $_width = min($width, $_options['width']);
         $_height = min($height, $_options['height']);
         $_img_user = imagecreate($width, $height);
         $background = imagecolorallocate($_img_user, 255, 255, 255);
         //	Copy and resample the image
         imagecopyresampled($_img_user, $_img_cropped, 0, 0, 0, 0, $_width, $_height, $_options['width'], $_options['height']);
         return $_img_user;
     } else {
         return $_img_cropped;
     }
 }
 protected function writeLine($image, $text)
 {
     $resource = $image->getAdapter()->getHolder();
     $box = imageTTFBbox($this->size, $this->angle, $this->font, $this->text);
     $textwidth = abs($box[4] - $box[0]) - 4;
     $textheight = abs($box[5] - $box[1]) - 4;
     $rgb = sscanf($this->color, '#%2x%2x%2x');
     $color = imagecolorallocate($resource, $rgb[0], $rgb[1], $rgb[2]);
     // disable alpha handling to enable font rendering
     imagealphablending($resource, true);
     imagettftext($resource, $this->size, $this->angle, $this->x, $this->y + $textheight, $color, $this->font, $this->text);
     return $image;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @access protected
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $this->font = $this->font_dir . DIRECTORY_SEPARATOR . $this->font . '.ttf';
     $box = imageTTFBbox($this->size, $this->angle, $this->font, $this->text);
     $textwidth = abs($box[4] - $box[0]) - 4;
     $textheight = abs($box[5] - $box[1]) - 4;
     $rgb = sscanf($this->color, '#%2x%2x%2x');
     $color = imagecolorallocate($resource, $rgb[0], $rgb[1], $rgb[2]);
     imagettftext($resource, $this->size, $this->angle, $this->x, $this->y + $textheight, $color, $this->font, $this->text);
     return $image;
 }
Beispiel #11
0
 static function placeholderImage($width, $height, $bg_color = false, $text_color = false, $icon_path = false, $text_string = false)
 {
     // Check size
     $width = $width > 2000 ? 2000 : $width;
     $height = $height > 2000 ? 2000 : $height;
     // Check colors
     $bg_color = !$bg_color && $bg_color != "000" && $bg_color != "000000" ? "CCCCCC" : ltrim($bg_color, "#");
     $text_color = !$text_color && $text_color != "000" && $text_color != "000000" ? "666666" : ltrim($text_color, "#");
     // Set text
     $text = $text_string;
     if ($icon_path) {
         $text = "";
     } else {
         if (!$text_string) {
             $text = $width . " X " . $height;
         }
     }
     // Create image
     $image = imagecreatetruecolor($width, $height);
     // Build rgba from hex
     $bg_color = imagecolorallocate($image, base_convert(substr($bg_color, 0, 2), 16, 10), base_convert(substr($bg_color, 2, 2), 16, 10), base_convert(substr($bg_color, 4, 2), 16, 10));
     $text_color = imagecolorallocate($image, base_convert(substr($text_color, 0, 2), 16, 10), base_convert(substr($text_color, 2, 2), 16, 10), base_convert(substr($text_color, 4, 2), 16, 10));
     // Fill image
     imagefill($image, 0, 0, $bg_color);
     // Add icon if provided
     if ($icon_path) {
         $icon_size = getimagesize($icon_path);
         $icon_width = $icon_size[0];
         $icon_height = $icon_size[1];
         $icon_x = ($width - $icon_width) / 2;
         $icon_y = ($height - $icon_height) / 2;
         $ext = strtolower(substr($icon_path, -3));
         if ($ext == "jpg" || $ext == "peg") {
             $icon = imagecreatefromjpeg($icon_path);
         } elseif ($ext == "gif") {
             $icon = imagecreatefromgif($icon_path);
         } else {
             $icon = imagecreatefrompng($icon_path);
         }
         imagesavealpha($icon, true);
         imagealphablending($icon, true);
         imagecopyresampled($image, $icon, $icon_x, $icon_y, 0, 0, $icon_width, $icon_height, $icon_width, $icon_height);
         // Add text if provided or default to size
     } elseif ($text) {
         $font = BigTree::path("inc/lib/fonts/arial.ttf");
         $fontsize = $width > $height ? $height / 15 : $width / 15;
         $textpos = imageTTFBbox($fontsize, 0, $font, $text);
         imagettftext($image, $fontsize, 0, ($width - $textpos[2]) / 2, ($height - $textpos[5]) / 2, $text_color, $font, $text);
     }
     // Serve image and die
     header("Content-Type: image/png");
     imagepng($image);
     imagedestroy($image);
     die;
 }
 function _555()
 {
     $b1 = imageTTFBbox($this->_112, 0, $this->_111, $this->_113);
     $b2 = $b1[4];
     $b3 = abs($b1[5]);
     $im = imageCreateTrueColor($b1[4], abs($b1[5]) + 2);
     imageFill($im, 0, 0, imageColorAllocate($im, 255, 255, 255));
     imagettftext($im, $this->_112, 0, 0, $b3, imageColorAllocate($im, 0, 0, 0), $this->_111, $this->_113);
     $this->_114 = $x = imageSX($im);
     $this->_115 = $y = imageSY($im);
     $c = 0;
     $q = 1;
     $this->_057[0] = 0;
     for ($i = 0; $i < $x; $i++) {
         for ($j = 0; $j < $y; $j++) {
             $p = imageColorsForIndex($im, imageColorAt($im, $i, $j));
             if ($p['red'] < 128 && $p['green'] < 128 && $p['blue'] < 128) {
                 $this->_057[$q] = $i;
                 $this->_057[$q + 1] = $j;
                 $q += 2;
                 $c += 2;
             }
         }
     }
     $this->_057[0] = $c;
     $this->_435($this->_116);
 }
Beispiel #13
0
 /**
  * Show a multi-area chart
  *
  * @param $raw_datas : an array with :
  *    - key 'datas', ex : array( 'test1' => 15, 'test2' => 25)
  *    - key 'unit', ex : '%', 'Kg' (optionnal)
  *    - key 'spline', curves line (boolean - optionnal)
  * @param $title : title of the chart
  * @param $desc : description of the chart (optionnal)
  * @param $show_label : behavior of the graph labels,
  *                      values : 'hover', 'never', 'always' (optionnal)
  * @param $export : keep only svg to export (optionnal)
  * @return nothing
  */
 function showGArea($params)
 {
     global $LANG;
     $criterias = PluginMreportingCommon::initGraphParams($params);
     foreach ($criterias as $key => $val) {
         ${$key} = $val;
     }
     //$rand = $opt['rand'];
     $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
     foreach ($configs as $k => $v) {
         ${$k} = $v;
     }
     if (self::DEBUG_GRAPH && isset($raw_datas)) {
         Toolbox::logdebug($raw_datas);
     }
     if (isset($raw_datas['datas'])) {
         $datas = $raw_datas['datas'];
     } else {
         $datas = array();
     }
     $options = array("title" => $title, "desc" => $desc, "randname" => $randname, "export" => $export, "delay" => $delay, "short_classname" => $opt["short_classname"]);
     $this->initGraph($options);
     if (count($datas) <= 0) {
         if ($export != "odtall") {
             echo $LANG['plugin_mreporting']["error"][1];
             $end['opt']["export"] = false;
             $end['opt']["randname"] = false;
             $end['opt']["f_name"] = $opt['f_name'];
             $end['opt']["class"] = $opt['class'];
             PluginMreportingCommon::endGraph($end);
         }
         return false;
     }
     $labels2 = $raw_datas['labels2'];
     $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
     $raw_datas['datas'] = $datas;
     $values = array_values($datas);
     $labels = array_keys($datas);
     $max = 1;
     foreach ($values as $line) {
         foreach ($line as $label2 => $value) {
             if ($value > $max) {
                 $max = $value;
             }
         }
     }
     if ($max == 1 && $unit == '%') {
         $max = 100;
     }
     $nb = count($labels2);
     $width = $this->width;
     $nb_bar = count($datas);
     if ($nb_bar > 1) {
         $percent = 2 * (450 + 18 * $nb_bar) / (18 * $nb_bar * 100);
     } else {
         $percent = 0.2;
     }
     $height = $percent * 450 + 18 * $nb_bar;
     $delta = 450 - $height;
     $height_tot = 450 + $height;
     $width_line = ($width - 45) / $nb;
     $index1 = 0;
     $index3 = 1;
     $step = ceil($nb / 20);
     //create image
     $image = imagecreatetruecolor($width, $height_tot);
     if ($show_graph) {
         //colors
         $palette = self::getPalette($nb_bar);
         $alphapalette = self::getPalette($nb_bar, "50");
         $darkerpalette = self::getDarkerPalette($nb_bar);
         //background
         $bg_color = $this->white;
         imagefilledrectangle($image, 0, 0, $width - 1, $height_tot - 1, $bg_color);
         //draw x-axis grey step line and value ticks
         $xstep = round(($height + $delta + 40) / 13);
         for ($i = 0; $i < 13; $i++) {
             $yaxis = $height_tot - 30 - $xstep * $i;
             //horizontal grey lines
             imageLine($image, 30, $yaxis, 30 + $width_line * ($nb - 1), $yaxis, $this->grey);
             //value ticks
             if ($i * $max / 12 < 10) {
                 $val = round($i * $max / 12, 1);
             } else {
                 $val = round($i * $max / 12);
             }
             $box = @imageTTFBbox($this->fontsize - 1, $this->fontangle, $this->font, $val);
             $textwidth = abs($box[4] - $box[0]);
             imagettftext($image, $this->fontsize - 1, $this->fontangle, 25 - $textwidth, $yaxis + 5, $this->darkgrey, $this->font, $val);
         }
         //draw y-axis vertical grey step line
         for ($i = 0; $i < $nb; $i++) {
             $xaxis = 30 + $width_line * $i;
             imageLine($image, $xaxis, $height - 40, $xaxis, $height_tot, $this->grey);
         }
         //draw y-axis
         imageLine($image, 30, $height - 40, 30, $height_tot - 25, $this->black);
         //draw y-axis
         imageLine($image, 30, $height_tot - 30, $width - 50, $height_tot - 30, $this->black);
         //create border on export
         if ($export) {
             imagerectangle($image, 0, 0, $width - 1, $height_tot - 1, $this->black);
         }
         //on png graph, no way to draw curved polygons, force area reports to be linear
         if ($area) {
             $spline = false;
         }
         //add title on export
         if ($export) {
             imagettftext($image, $this->fontsize + 1, $this->fontangle, 10, 20, $this->black, $this->font, $title);
         }
         //parse datas
         foreach ($datas as $label => $data) {
             $aCoords = array();
             $index2 = 0;
             $old_data = 0;
             //parse line
             foreach ($data as $subdata) {
                 //if first index, continue
                 if ($index2 == 0) {
                     $old_data = $subdata;
                     $index2++;
                     continue;
                 }
                 // determine coords
                 $x1 = $index2 * $width_line - $width_line + 30;
                 $y1 = $height_tot - 30 - $old_data * ($height_tot - $height) / $max;
                 $x2 = $x1 + $width_line;
                 $y2 = $height_tot - 30 - $subdata * ($height_tot - $height) / $max;
                 //in case of area chart fill under point space
                 if ($area > 0) {
                     $points = array($x1, $y1, $x2, $y2, $x2, $height_tot - 30, $x1, $height_tot - 30);
                     imagefilledpolygon($image, $points, 4, $alphapalette[$index1]);
                 }
                 //trace lines between points (if linear)
                 if (!$spline) {
                     $this->imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $palette[$index1]);
                 }
                 $aCoords[$x1] = $y1;
                 $old_data = $subdata;
                 $index2++;
                 $index3++;
             }
             //if curved spline activated, draw cubic spline for the current line
             if ($spline) {
                 $aCoords[$x2] = $y2;
                 $this->imageCubicSmoothLine($image, $palette[$index1], $aCoords);
                 $index2 = 0;
                 $old_data = 0;
                 $old_label = "";
             }
             //draw labels and dots
             $index2 = 0;
             $old_data = 0;
             foreach ($data as $subdata) {
                 //if first index, continue
                 if ($index2 == 0) {
                     $old_data = $subdata;
                     $old_label = $label;
                     $index2++;
                     continue;
                 }
                 // determine coords
                 $x1 = $index2 * $width_line - $width_line + 30;
                 $y1 = $height_tot - 30 - $old_data * ($height_tot - $height) / $max;
                 $x2 = $x1 + $width_line;
                 $y2 = $height_tot - 30 - $subdata * ($height_tot - $height) / $max;
                 //trace dots
                 $color_rbg = self::colorHexToRGB($darkerpalette[$index1]);
                 imageSmoothArc($image, $x1 - 1, $y1 - 1, 7, 7, $color_rbg, 0, 2 * M_PI);
                 imageSmoothArc($image, $x1 - 1, $y1 - 1, 4, 4, array(255, 255, 255, 0), 0, 2 * M_PI);
                 //display values label
                 if ($show_label == "always" || $show_label == "hover") {
                     imagettftext($image, $this->fontsize - 2, $this->fontangle, $index2 == 1 ? $x1 : $x1 - 6, $y1 - 5, $darkerpalette[$index1], $this->font, $old_data);
                 }
                 //show x-axis ticks
                 if ($step != 0 && $index3 / $step == round($index3 / $step)) {
                     imageline($image, $x1, $height_tot - 30, $x1, $height_tot - 27, $darkerpalette[$index1]);
                 }
                 $old_data = $subdata;
                 $old_label = $label;
                 $index2++;
                 $index3++;
             }
             /*** display last value ***/
             if (isset($x2)) {
                 //trace dots
                 $color_rbg = self::colorHexToRGB($darkerpalette[$index1]);
                 imageSmoothArc($image, $x2 - 1, $y2 - 1, 7, 7, $color_rbg, 0, 2 * M_PI);
                 imageSmoothArc($image, $x2 - 1, $y2 - 1, 4, 4, array(255, 255, 255, 0), 0, 2 * M_PI);
                 //display value label
                 if ($show_label == "always" || $show_label == "hover") {
                     imagettftext($image, $this->fontsize - 2, $this->fontangle, $index2 == 1 ? $x2 : $x2 - 6, $y2 - 5, $darkerpalette[$index1], $this->font, $old_data);
                 }
             }
             /*** end display last value ***/
             $index1++;
         }
         //display labels2
         $index = 0;
         foreach ($labels2 as $label) {
             $x = $index * $width_line + 20;
             if ($step != 0 && $index / $step == round($index / $step)) {
                 imagettftext($image, $this->fontsize - 1, $this->fontangle, $x, $height_tot - 10, $this->black, $this->font, $label);
             }
             $index++;
         }
         //legend (align left)
         $index = 0;
         foreach ($labels as $label) {
             //legend label
             $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $label);
             $textwidth = abs($box[4] - $box[0]);
             $textheight = abs($box[5] - $box[1]);
             imagettftext($image, $this->fontsize - 1, $this->fontangle, 20, 35 + $index * 14, $this->black, $this->font, $label);
             //legend circle
             $color_rbg = self::colorHexToRGB($palette[$index]);
             imageSmoothArc($image, 10, 30 + $index * 14, 7, 7, $color_rbg, 0, 2 * M_PI);
             $index++;
         }
     }
     //generate image
     $params = array("image" => $image, "export" => $export, "f_name" => $opt['f_name'], "class" => $opt['class'], "title" => $title, "randname" => $randname, "raw_datas" => $raw_datas, "withdata" => $opt['withdata']);
     $contents = $this->generateImage($params);
     if ($show_graph) {
         $this->showImage($contents, $export);
     }
     $opt['randname'] = $randname;
     $options = array("opt" => $opt, "export" => $export, "datas" => $datas, "labels2" => $labels2, "flip_data" => $flip_data, "unit" => $unit);
     PluginMreportingCommon::endGraph($options);
 }
 function textoverlay($text, $image_p, $new_width, $new_height)
 {
     $fontstyle = 5;
     // 1,2,3,4 or 5
     $fontcolor = $this->gvar['text_color'];
     $fontshadowcolor = $this->gvar['text_shadow_color'];
     $ttfont = isset($this->set['map_text_font']) ? $this->set['map_text_font'] : WP_PLUGIN_DIR . '/visitor-maps/vmfont.ttf';
     $fontsize = 11;
     # size for True Type Font $ttfont only (8-18 recommended)
     $textalign = $this->gvar['text_align'];
     $xmargin = 5;
     $ymargin = 0;
     if (!preg_match('#[a-z0-9]{6}#i', $fontcolor)) {
         $fontcolor = 'FFFFFF';
     }
     # default white
     if (!preg_match('#[a-z0-9]{6}#i', $fontshadowcolor)) {
         $fontshadowcolor = '808080';
     }
     # default grey
     $fcint = hexdec("#{$fontcolor}");
     $fsint = hexdec("#{$fontshadowcolor}");
     $fcarr = array("red" => 0xff & $fcint >> 0x10, "green" => 0xff & $fcint >> 0x8, "blue" => 0xff & $fcint);
     $fsarr = array("red" => 0xff & $fsint >> 0x10, "green" => 0xff & $fsint >> 0x8, "blue" => 0xff & $fsint);
     $fcolor = imagecolorallocate($image_p, $fcarr["red"], $fcarr["green"], $fcarr["blue"]);
     $fscolor = imagecolorallocate($image_p, $fsarr["red"], $fsarr["green"], $fsarr["blue"]);
     if ($ttfont != '') {
         # using ttf fonts
         $_b = imageTTFBbox($fontsize, 0, $ttfont, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
         $fontheight = abs($_b[7] - $_b[1]);
     } else {
         $font = $fontstyle;
         # using built in fonts, find alignment
         if ($font < 0 || $font > 5) {
             $font = 1;
         }
         $fontwidth = ImageFontWidth($font);
         $fontheight = ImageFontHeight($font);
     }
     $text = preg_replace("/\r/", '', $text);
     # wordwrap line if too many characters on one line
     if ($ttfont != '') {
         # array lines
         $lines = explode("\n", $text);
         $lines = $this->ttf_wordwrap($lines, $ttfont, $fontsize, floor($new_width - $xmargin * 2));
     } else {
         $maxcharsperline = floor(($new_width - $xmargin * 2) / $fontwidth);
         $text = wordwrap($text, $maxcharsperline, "\n", 1);
         # array lines
         $lines = explode("\n", $text);
     }
     # determine alignment
     $align = 'ul';
     # default upper left
     if ($textalign == 'll') {
         $align = 'll';
     }
     // lowerleft
     if ($textalign == 'ul') {
         $align = 'ul';
     }
     // upperleft
     if ($textalign == 'lr') {
         $align = 'lr';
     }
     // lowerright
     if ($textalign == 'ur') {
         $align = 'ur';
     }
     // upperright
     if ($textalign == 'c') {
         $align = 'c';
     }
     // center
     if ($textalign == 'ct') {
         $align = 'ct';
     }
     // centertop
     if ($textalign == 'cb') {
         $align = 'cb';
     }
     // centerbottom
     # find start position for each text position type
     if ($align == 'ul') {
         $x = $xmargin;
         $y = $ymargin;
     }
     if ($align == 'll') {
         $x = $xmargin;
         $y = $new_height - ($fontheight + $ymargin);
         $lines = array_reverse($lines);
     }
     if ($align == 'ur') {
         $y = $ymargin;
     }
     if ($align == 'lr') {
         $x = $xmargin;
         $y = $new_height - ($fontheight + $ymargin);
         $lines = array_reverse($lines);
     }
     if ($align == 'ct') {
         $y = $ymargin;
     }
     if ($align == 'cb') {
         $x = $xmargin;
         $y = $new_height - ($fontheight + $ymargin);
         $lines = array_reverse($lines);
     }
     if ($align == 'c') {
         $y = $new_height / 2 - count($lines) * $fontheight / 2;
     }
     if ($ttfont != '') {
         $y += $fontsize;
     }
     # fudge adjustment for truetype margin
     while (list($numl, $line) = each($lines)) {
         # adjust position for each text position type
         if ($ttfont != '') {
             $_b = imageTTFBbox($fontsize, 0, $ttfont, $line);
             $stringwidth = abs($_b[2] - $_b[0]);
         } else {
             $stringwidth = strlen($line) * $fontwidth;
         }
         if ($align == 'ur' || $align == 'lr') {
             $x = $new_width - $stringwidth - $xmargin;
         }
         if ($align == 'ct' || $align == 'cb' || $align == 'c') {
             $x = $new_width / 2 - $stringwidth / 2;
         }
         if ($ttfont != '') {
             # write truetype font text with slight SE shadow to standout
             imagettftext($image_p, $fontsize, 0, $x - 1, $y, $fscolor, $ttfont, $line);
             imagettftext($image_p, $fontsize, 0, $x, $y - 1, $fcolor, $ttfont, $line);
         } else {
             # write text with slight SE shadow to standout
             imagestring($image_p, $font, $x - 1, $y, $line, $fscolor);
             imagestring($image_p, $font, $x, $y - 1, $line, $fcolor);
         }
         # adjust position for each text position type
         if ($align == 'ul' || $align == 'ur' || $align == 'ct' || $align == 'c') {
             $y += $fontheight;
         }
         if ($align == 'll' || $align == 'lr' || $align == 'cb') {
             $y -= $fontheight;
         }
     }
     # end while
 }
Beispiel #15
0
$im = ImageCreateTrueColor($imgmaxxroom, $imgmaxyroom);
$black = ImageColorAllocate($im, 0, 0, 0);
$bg1p = ImageColorAllocate($im, $bg1_R, $bg1_G, $bg1_B);
$bg2p = ImageColorAllocate($im, $buttonBg_R, $buttonBg_G, $buttonBg_B);
$bg3p = ImageColorAllocate($im, $fontcol_grap_R, $fontcol_grap_G, $fontcol_grap_B);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray = ImageColorAllocate($im, 133, 133, 133);
$red = ImageColorAllocate($im, 255, 0, 0);
$green = ImageColorAllocate($im, 0, 255, 0);
$yellow = ImageColorAllocate($im, 255, 255, 0);
$orange = ImageColorAllocate($im, 255, 230, 25);
if ($room == $showroom) {
    $imgcolor = $bg1p;
    $txtcolor = $white;
} else {
    $imgcolor = $bg2p;
    $txtcolor = $bg3p;
}
ImageFill($im, 0, 0, $imgcolor);
ImageRectangle($im, 0, 0, $imgmaxxroom - 1, $imgmaxyroom - 1, $white);
###ttf
$text = $room;
$box = @imageTTFBbox($roomfontsizetitel, 0, $fontttfb, $text);
$textwidth = abs($box[4] - $box[0]);
$textheight = abs($box[5] - $box[1]);
$xcord = $imgmaxxroom / 2 - $textwidth / 2 - 2;
#	$ycord = ($imgmaxyroom/2)+($textheight/2);
$ycord = $imgmaxyroom / 3 + $roomfontsizetitel;
ImageTTFText($im, $roomfontsizetitel, 0, $xcord, $ycord, $txtcolor, $fontttfb, $text);
header("Content-type: image/png");
imagePng($im);
Beispiel #16
0
$fontsize = 7;
$box = @imageTTFBbox($fontsize, 0, $fontttfb, $text);
$textwidth = abs($box[4] - $box[0]);
$textheight = abs($box[5] - $box[1]);
$xcord = $imgmaxxfs20 / 2 - $textwidth / 2 - 2;
$ycord = $imgmaxyfs20 / 2 + 23;
ImageTTFText($im, $fontsize, 0, $xcord, $ycord, $txtcolor, $fontttfb, $text);
$text = $date_button;
$box = @imageTTFBbox($fontsize, 0, $fontttf, $text);
$textwidth = abs($box[4] - $box[0]);
$textheight = abs($box[5] - $box[1]);
#$xcord = ($imgmaxxfs20/2)-($textwidth/2)+53;
$xcord = $imgmaxxfs20 - $textwidth - 2;
$ycord = $imgmaxyfs20 / 2 + 33;
ImageTTFText($im, $fontsize, 0, $xcord, $ycord, $txtcolor, $fontttf, $text);
$text = $time_button;
$box = @imageTTFBbox($fontsize, 0, $fontttf, $text);
$textwidth = abs($box[4] - $box[0]);
$textheight = abs($box[5] - $box[1]);
#$xcord = ($imgmaxxfs20/2)-($textwidth/2)-58;
$xcord = 3;
$ycord = $imgmaxyfs20 / 2 + 33;
ImageTTFText($im, $fontsize, 0, $xcord, $ycord, $txtcolor, $fontttf, $text);
$txtcolor = $bg3p;
ImageTTFText($im, $fs20fontsizetitel, 0, 5, 15, $txtcolor, $fontttfb, $drawfs20);
if ($room != '' and $roomname == '1') {
    ImageTTFText($im, 7, 0, 5, 26, $txtcolor, $fontttf, $txtroom . $room);
}
imagePng($im, $savefile);
header("Content-type: image/png");
imagePng($im);
Beispiel #17
0
 /**
  * Diplay a given message as png image 
  *
  * @param String $msg Message to display
  *
  * @return Void
  */
 public function displayMessage($msg)
 {
     //ttf from jpgraph
     $ttf = new TTF();
     Chart_TTFFactory::setUserFont($ttf);
     //Calculate the baseline
     // @see http://www.php.net/manual/fr/function.imagettfbbox.php#75333
     //this should be above baseline
     $test2 = "H";
     //some of these additional letters should go below it
     $test3 = "Hjgqp";
     //get the dimension for these two:
     $box2 = imageTTFBbox(10, 0, $ttf->File(FF_USERFONT), $test2);
     $box3 = imageTTFBbox(10, 0, $ttf->File(FF_USERFONT), $test3);
     $baseline = abs(abs($box2[5]) + abs($box2[1]) - (abs($box3[5]) + abs($box3[1])));
     $bbox = imageTTFBbox(10, 0, $ttf->File(FF_USERFONT), $msg);
     if ($im = @imagecreate($bbox[2] - $bbox[6], $bbox[3] - $bbox[5])) {
         $backgroundColor = imagecolorallocate($im, 255, 255, 255);
         $textColor = imagecolorallocate($im, 64, 64, 64);
         imagettftext($im, 10, 0, 0, $bbox[3] - $bbox[5] - $baseline, $textColor, $ttf->File(FF_USERFONT), $msg);
         header("Content-type: image/png");
         imagepng($im);
         imagedestroy($im);
     }
 }
Beispiel #18
0
 /**
  * Apply the transform to the sfImage object.
  *
  * @access protected
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $this->font = $this->font_dir . DIRECTORY_SEPARATOR . $this->font . '.ttf';
     $box = imageTTFBbox($this->size, $this->angle, $this->font, $this->text);
     $textwidth = abs($box[4] - $box[0]);
     $textheight = abs($box[5] - $box[1]);
     $rgb = sscanf($this->color, '#%2x%2x%2x');
     $color = imagecolorallocate($resource, $rgb[0], $rgb[1], $rgb[2]);
     // disable alpha handling to enable font rendering
     imagealphablending($resource, true);
     // textheight nem korrekt, mert ékezetes és száras betűk esetén ez nagyobb lesz, mint a font méret
     imagettftext($resource, $this->size, $this->angle, $this->x, $this->y + $this->size, $color, $this->font, $this->text);
     return $image;
 }