function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 0, 0, 0); $noise_color = imagecolorallocate($image, 226, 82, 207); $noise_color1 = imagecolorallocate($image, 64, 179, 255); $noise_color2 = imagecolorallocate($image, 255, 204, 190); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 250; $i++) { imageellipse($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color2); } /* generate random dots in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imagedashedline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color1); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imagedashedline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function'); /* output captcha image to browser */ imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; }
// red color $blue = imagecolorallocate($image, 0, 0, 255); // blue color $green = imagecolorallocate($image, 0, 255, 0); // green color $black = imagecolorallocate($image, 0, 0, 0); // black color imageline($image, 0, $nolla, $width, $nolla, $black); // draw zero line in middle of picture imagestring($image, 5, 5, $nolla + 5, '0 C', $black); // write 0 c near zero line imagedashedline($image, 0, $nolla + 20 * $kerroin, $width, $nolla + 20 * $kerroin, $black); // draw -20 C line imagestring($image, 5, 5, $nolla + 20 * $kerroin + 5, '-20 C', $black); // write -20 C near-20 c line imagedashedline($image, 0, $nolla - 20 * $kerroin, $width, $nolla - 20 * $kerroin, $black); // draw 20 C line imagestring($image, 5, 5, $nolla - 20 * $kerroin + 5, '20 C', $black); // write 20 near 20 c line imagestring($image, 5, 10, 10, 'Ulkolampotila:', $black); imagestring($image, 4, 10, 25, 'Current', $green); imagestring($image, 4, 10, 40, 'Max', $red); imagestring($image, 4, 10, 55, 'Min', $blue); // write on the top corner out temperature,current,max,min @($line = explode(" ", $file[$i])); // using space for delimiter separates values to array @($temp_a = $line[5] * $kerroin); // setting first temperature point @($maxtemp_a = $line[6] * $kerroin); // setting first max temp point @($mintemp_a = $line[7] * $kerroin);
public function create() { $pxHeight = $this->pxPaperSize['height'] / 2; // we only use a quadrant $pxWidth = $this->pxPaperSize['width'] / 2; // we only use a quadrant $im = imagecreatetruecolor($pxWidth, $pxHeight); if (!$im) { throw new Exception(__('Failed to create prescription')); } $font = $this->fonts['regular']; $fontBold = $this->fonts['bold']; $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, $this->pxPaperSize['width'], $this->pxPaperSize['height'], $white); // deduct 1pixel to the right vertical and lower horizontal $width = $pxWidth - 1; $height = $pxHeight - 1; imagedashedline($im, 0, 0, 0, $height, $black); // left vertical imagedashedline($im, 0, 0, $width, 0, $black); // upper horizontal imagedashedline($im, $width, 0, $width, $height, $black); // right vertical imagedashedline($im, 0, $height, $width, $height, $black); // lower horizontal $x = 0; $y = 20; $size = 11; $angle = 0; $texts = array(); $texts[] = $this->prescriberName; $texts[] = 'S.L.# ' . $this->prescriberStateLicenseNumber . ' D.E.A.# ' . $this->prescriberDeaNumber; foreach ($texts as $text) { $box = imagettfbbox($size, $angle, $fontBold, $text); $x = abs(ceil(($pxWidth - $box[2]) / 2)); $y += 20; imagettftext($im, $size, 0, $x, $y, $black, $fontBold, $text); } $texts = array(); $texts[] = $this->practiceName; $texts[] = $this->practiceAddress; $texts[] = $this->practiceCity . ', ' . $this->practiceState . ' ' . $this->practicePostalCode; $y += 20; foreach ($texts as $text) { $box = imagettfbbox($size, $angle, $font, $text); $x = abs(ceil(($pxWidth - $box[2]) / 2)); $y += 20; imagettftext($im, $size, 0, $x, $y, $black, $font, $text); } $data = array(); $data[] = array('label' => __('Patient Name'), 'text' => $this->patientName); $data[] = array('label' => __('Address'), 'text' => $this->patientAddress . ', ' . $this->patientCity . ' ' . $this->patientState . ' ' . $this->patientPostalCode); $data[] = array(array('label' => __('Date'), 'text' => $this->medicationDatePrescribed), array('label' => __('DOB'), 'text' => $this->patientDateOfBirth)); $data[] = array('label' => __('Description'), 'text' => $this->medicationDescription); $data[] = array('label' => _('Comments'), 'text' => $this->medicationComment); $data[] = array(array('label' => __('Quantity'), 'text' => $this->medicationQuantity), array('label' => __('Refill'), 'text' => $this->medicationRefills . ' ' . __('Times'))); $data[] = array('label' => __('Directions'), 'text' => $this->medicationDirections); $permitted = ''; if (!$this->medicationSubstitution) { $permitted = __('Not') . ' '; } $data[] = array('label' => '', 'text' => __('Substitution') . ' ' . $permitted . __('Permitted')); $size = 10; $labelMaxWidth = 0; $textMaxWidth = 0; foreach ($data as $key => $value) { if (!isset($value['label'])) { foreach ($value as $k => $v) { $label = $v['label']; $box = imagettfbbox($size, $angle, $font, $label); $maxWidth = abs(ceil($box[2] - $box[0])); $data[$key][$k]['labelWidth'] = $maxWidth; if ($maxWidth > $labelMaxWidth) { $labelMaxWidth = $maxWidth; } $text = $v['text']; $box = imagettfbbox($size, $angle, $font, $text); $maxWidth = abs(ceil($box[2] - $box[0])); $data[$key][$k]['textWidth'] = $maxWidth; if ($maxWidth > $textMaxWidth) { $textMaxWidth = $maxWidth; } } } else { $label = $value['label']; $box = imagettfbbox($size, $angle, $font, $label); $maxWidth = abs(ceil($box[2] - $box[0])); $data[$key]['labelWidth'] = $maxWidth; if ($maxWidth > $labelMaxWidth) { $labelMaxWidth = $maxWidth; } $text = $value['text']; $box = imagettfbbox($size, $angle, $font, $text); $maxWidth = abs(ceil($box[2] - $box[0])); $data[$key]['textWidth'] = $maxWidth; if ($maxWidth > $textMaxWidth) { $textMaxWidth = $maxWidth; } } } $y += 30; $angle = 0; $ttfData = array(); $ttfData['im'] = $im; $ttfData['size'] = $size; $ttfData['angle'] = $angle; $ttfData['color'] = $black; $ttfData['font'] = $font; $widths = array(); $widths['textMaxWidth'] = $textMaxWidth; $widths['labelMaxWidth'] = $labelMaxWidth; $widths['pxWidth'] = $pxWidth; foreach ($data as $value) { $y += 20; $x = 20; $widths['pxWidth'] = $pxWidth; if (!isset($value['label'])) { $firstItem = true; $maxY = $y; $valCtr = count($value); $widths['pxWidth'] = $pxWidth / $valCtr; $multiline = array('offset' => 0, 'length' => $valCtr); for ($i = 0; $i < $valCtr; $i++) { $tmpY = $y; $val = $value[$i]; $multiline['offset'] = $i; if ($firstItem) { $this->_createImageText($x, $tmpY, $val, $ttfData, $widths, true, $multiline); $firstItem = false; } else { $this->_createImageText($x, $tmpY, $val, $ttfData, $widths, false, $multiline); } if ($tmpY > $maxY) { $maxY = $tmpY; } } $y = $maxY; } else { $this->_createImageText($x, $y, $value, $ttfData, $widths, true); } } $text = __('Signature'); $y += 40; $x = 20; imagettftext($im, $size, 0, $x, $y, $black, $font, $text); // Signature if (strlen($this->prescriberSignature) > 0 && file_exists($this->prescriberSignature)) { $srcImageFile = $this->prescriberSignature; do { $imageSize = getimagesize($srcImageFile); if (!$imageSize || $imageSize[2] < 1 || $imageSize[2] > 16) { break; } $srcIm = null; switch ($imageSize[2]) { case 1: // IMAGETYPE_GIF $srcIm = imagecreatefromgif($srcImageFile); break; case 2: // IMAGETYPE_JPEG $srcIm = imagecreatefromjpeg($srcImageFile); break; case 3: // IMAGETYPE_PNG $srcIm = imagecreatefrompng($srcImageFile); break; case 4: // IMAGETYPE_SWF // IMAGETYPE_SWF case 5: // IMAGETYPE_PSD // IMAGETYPE_PSD case 6: // IMAGETYPE_BMP // IMAGETYPE_BMP case 7: // IMAGETYPE_TIFF_II (intel byte order) // IMAGETYPE_TIFF_II (intel byte order) case 8: // IMAGETYPE_TIFF_MM (motorola byte order) // IMAGETYPE_TIFF_MM (motorola byte order) case 9: // IMAGETYPE_JPC // IMAGETYPE_JPC case 10: // IMAGETYPE_JP2 // IMAGETYPE_JP2 case 11: // IMAGETYPE_JPX // IMAGETYPE_JPX case 12: // IMAGETYPE_JB2 // IMAGETYPE_JB2 case 13: // IMAGETYPE_SWC // IMAGETYPE_SWC case 14: // IMAGETYPE_IFF break; case 15: // IMAGETYPE_WBMP $srcIm = imagecreatefromwbmp($srcImageFile); break; case 16: // IMAGETYPE_XBM $srcIm = imagecreatefromxbm($srcImageFile); break; } if (!$srcIm) { break; } $srcX = 0; $srcY = 0; $dimension = $imageSize; //getimagesize($srcImageFile); $srcWidth = $dimension[0]; $srcHeight = $dimension[1]; $dstIm = $im; $dstX = 120; $dstY = $y; // attach signature $dstWidth = 150; $dstHeight = 58; imagecopyresampled($dstIm, $srcIm, $dstX, $dstY, $srcX, $srcY, $dstWidth, $dstHeight, $srcWidth, $srcHeight); //imagecopy($dstIm,$srcIm,$dstX,$dstY,$srcX,$srcY,$srcWidth,$srcHeight); $x = $dstX; $y += $srcHeight + 10; $text = $this->prescriberName; imagettftext($im, $size, 0, $x, $y, $black, $fontBold, $text); } while (false); if (file_exists($srcImageFile)) { unlink($srcImageFile); } } // Footer $size = 8; $text = __('This prescription was generated by the ClearHealth EMR system'); $angle = 0; $box = imagettfbbox($size, $angle, $font, $text); $x = abs(ceil(($pxWidth - $box[2]) / 2)); $y = $pxHeight - 10; imagettftext($im, $size, 0, $x, $y, $black, $font, $text); // wrap the generated image in the whole paper size $srcIm = $im; $srcX = 0; $srcY = 0; $srcHeight = $pxHeight; $srcWidth = $pxWidth; $pxHeight *= 2; $pxWidth *= 2; $dstIm = imagecreatetruecolor($pxWidth, $pxHeight); if (!$dstIm) { throw new Exception(__('Failed to create prescription')); } imagefilledrectangle($dstIm, 0, 0, $this->pxPaperSize['width'], $this->pxPaperSize['height'], $white); $dstX = 0; $dstY = 0; imagecopy($dstIm, $srcIm, $dstX, $dstY, $srcX, $srcY, $srcWidth, $srcHeight); $tmpFile = tempnam('/tmp', 'ch30_'); $imFile = $tmpFile . '.png'; rename($tmpFile, $imFile); $this->imageFile = $imFile; imagepng($dstIm, $imFile); imagedestroy($im); imagedestroy($dstIm); }
function produce_page_graph($field, $beforekey, page $before, $afterkey, page $after, $width = 800, $height = 600, array $options = array()) { global $BASEDIR; $subdir = md5($beforekey . $afterkey . $before->name . $width . $height . serialize($options)); $name = $subdir . '/' . $field . '.png'; $path = $BASEDIR . '/cache/'; if (file_exists($path . $name) && empty($_GET['force'])) { return $name; } if (!is_dir($path . $subdir)) { mkdir($path . $subdir); chmod($path . $subdir, 0775); } $image = imagecreatetruecolor($width, $height); if (function_exists('imageantialias')) { imageantialias($image, true); } $colours = new stdClass(); $colours->black = imagecolorallocate($image, 0, 0, 0); $colours->white = imagecolorallocate($image, 255, 255, 255); $colours->shadow = imagecolorallocate($image, 200, 200, 200); $colours->beforepoint = imagecolorallocate($image, 165, 165, 255); $colours->afterpoint = imagecolorallocate($image, 255, 165, 165); $colours->beforeline = imagecolorallocate($image, 110, 110, 255); $colours->afterline = imagecolorallocate($image, 255, 110, 110); $colours->afterlineflat = imagecolorallocate($image, 255, 0, 0); $colours->afterlineave = imagecolorallocate($image, 255, 32, 32); $colours->beforelineflat = imagecolorallocate($image, 0, 0, 255); $colours->beforelineave = imagecolorallocate($image, 32, 32, 255); $x1 = 10; $x2 = $width - 10; $y1 = 30; $y2 = $height - 10; imagefill($image, 0, 0, $colours->white); imagefilledrectangle($image, $x1 - 2, $y1 + 2, $x2 + 2, $y2 + 2, $colours->shadow); imagefilledrectangle($image, $x1, $y1, $x2, $y2, $colours->white); imagerectangle($image, $x1, $y1, $x2, $y2, $colours->black); $graphheight = $y2 - $y1 - 2; $graphwidth = $x2 - $x1 - 2; $total = count($before->{$field}); $min = min(min($before->{$field}), min($after->{$field})); $max = max(max($before->{$field}), max($after->{$field})); $dmin = $min * 0.1; if ($min >= 10 && $min < 100) { $dmin = $min * 0.2; } else { if ($min >= 100 && $min < 1000) { $dmin = $min * 0.2; } else { if ($min >= 1000) { $dmin = $min * 0.01; } } } $min -= $dmin; $max += $dmin; if ($min > 0 && $min < 10) { $min = 0; } else { if ($min >= 10 && $min < 100) { $min = floor($min); } else { if ($min >= 100 && $min < 1000) { $min = round($min, -1); // Down } else { if ($min >= 1000) { $min = round($min, -3); // Down } } } } if ($max >= 10 && $max < 100) { $max = ceil($max); } else { if ($max >= 100 && $max < 1000) { $max = round($max, -1); // Up } else { if ($max >= 1000) { $max = round($max, -2); // Up } } } $lines = min($graphwidth, $total); $gap = ($graphwidth - $lines) / $lines; if ($gap < 0) { $gap = 0; } $range = $max - $min; if ($range > 0) { $ratio = $graphheight / $range; } else { $ratio = 1; } $b = reset($before->{$field}); $a = reset($after->{$field}); $pb = null; $pa = null; $px = null; $bc = null; $ac = null; $beforeaverages = array(); $afteraverages = array(); $averagesamplespace = max(20, $total / 20); for ($i = 1; $i < $lines; $i++) { $xpoint = $i + $x1 + ($i - 1) * $gap; $ybefore = $height - 10 - floor(($b - $min) * $ratio); $yafter = $height - 10 - floor(($a - $min) * $ratio); if ($i > $averagesamplespace / 2 && $i < $lines - $averagesamplespace / 2) { $beforechunk = array_slice($before->{$field}, $i - $averagesamplespace / 2, $averagesamplespace); $beforechunk = array_sum($beforechunk) / count($beforechunk); $beforechunk = $height - 10 - floor(($beforechunk - $min) * $ratio); $beforeaverages[$xpoint] = $beforechunk; $afterchunk = array_slice($after->{$field}, $i - $averagesamplespace / 2, $averagesamplespace); $afterchunk = array_sum($afterchunk) / count($afterchunk); $afterchunk = $height - 10 - floor(($afterchunk - $min) * $ratio); $afteraverages[$xpoint] = $afterchunk; } if ($gap > 0 && $px != null) { if ($gap > 3) { imagefilledellipse($image, $xpoint, $ybefore, 3, 3, $colours->beforepoint); imagefilledellipse($image, $xpoint, $yafter, 3, 3, $colours->afterpoint); } else { imagesetpixel($image, $xpoint, $ybefore, $colours->beforepoint); imagesetpixel($image, $xpoint, $yafter, $colours->afterpoint); } imageline($image, $px, $pb, $xpoint, $ybefore, $colours->beforeline); imageline($image, $px, $pa, $xpoint, $yafter, $colours->afterline); } $px = $xpoint; $pb = $ybefore; $pa = $yafter; $b = next($before->{$field}); $a = next($after->{$field}); } $ybefore = array_sum($before->{$field}) / $total - $min; $ybefore = $height - 10 - round($ybefore * $ratio, 1); $yafter = array_sum($after->{$field}) / $total - $min; $yafter = $height - 10 - round($yafter * $ratio, 1); imagedashedline($image, 11, $ybefore, $width - 12, $ybefore, $colours->beforelineflat); imagedashedline($image, 11, $yafter, $width - 12, $yafter, $colours->afterlineflat); $lastx = null; $lasty = null; foreach ($beforeaverages as $x => $y) { if ($lastx != null) { imageline($image, $lastx, $lasty, $x, $y, $colours->beforelineave); } $lastx = $x; $lasty = $y; } $lastx = null; $lasty = null; foreach ($afteraverages as $x => $y) { if ($lastx != null) { imageline($image, $lastx, $lasty, $x, $y, $colours->afterlineave); } $lastx = $x; $lasty = $y; } write_graph_y_labels($image, $min, $max, $width, $height, $colours->black); write_graph_title($image, $field, $width, $height, $colours->black); write_graph_legend($image, $colours, $width, $height); imagepng($image, $path . $name, 9); chmod($path . $name, 0775); return $name; }
<?php /* Prototype : bool imagedashedline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color ) * Description: Draws a dashed line. * This function is deprecated. Use combination of imagesetstyle() and imageline() instead. * Source code: ext/standard/image.c * Alias to functions: */ echo "Simple test of imagedashedline() function\n"; $dest = dirname(realpath(__FILE__)) . '/imagedashedline.png'; // create a blank image $image = imagecreatetruecolor(250, 250); // set the background color to black $bg = imagecolorallocate($image, 0, 0, 0); // red dashed lines $col_line = imagecolorallocate($image, 255, 0, 0); // draw a couple of vertical dashed lines imagedashedline($image, 100, 20, 100, 230, $col_line); imagedashedline($image, 150, 20, 150, 230, $col_line); // output the picture to a file imagepng($image, $dest); //check color of a point on edge.. $col1 = imagecolorat($image, 100, 230); // ..and a point on background $col2 = imagecolorat($image, 5, 5); $color1 = imagecolorsforindex($image, $col1); $color2 = imagecolorsforindex($image, $col2); var_dump($color1, $color2); imagedestroy($image); echo "Done\n";
echo imagesx($img).'x'.imagesy($img).'<br />'; */ $imgjpeg = imagecreate(600, 500); $imgjpeg = imagecreatetruecolor(500, 500); //真彩色图片颜色无法像调色板直接显示 $color1 = imagecolorallocate($imgjpeg, 0, 75, 0); $color2 = imagecolorallocate($imgjpeg, 255, 255, 0); //真彩色需填充,坐标-相邻所有相同色素点均改变 imagefill($imgjpeg, 0, 0, $color1); //imagefill($imgjpeg,30,30,$color2); for ($i = 1; $i <= 30; $i++) { $x1 = mt_rand(0, 500); $y1 = mt_rand(0, 500); $x2 = mt_rand(0, 500); $y2 = mt_rand(0, 500); $color3 = imagecolorallocate($imgjpeg, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imageline($imgjpeg, $x1, $y1, $x2, $y2, $color3); $x1 = mt_rand(0, 500); //$y1=mt_rand(0,500); //$x2=mt_rand(0,500); $y2 = mt_rand(0, 500); imagedashedline($imgjpeg, $x1, $y1, $x2, $y2, $color3); } for ($i = 0; $i <= 500; $i++) { imagesetpixel($imgjpeg, $i, mt_rand(0, $i), $color2); } imagerectangle($imgjpeg, 100, 100, 400, 400, $color2); //显示图片 imagejpeg($imgjpeg); //释放资源 imagedestroy($imgjpeg);
function myDrawLine($image, $x1, $y1, $x2, $y2, $color, $drawtype) { if ($drawtype == MAP_LINK_DRAWTYPE_BOLD_LINE) { zbx_imagealine($image, $x1, $y1, $x2, $y2, $color, LINE_TYPE_BOLD); } elseif ($drawtype == MAP_LINK_DRAWTYPE_DASHED_LINE) { if (function_exists('imagesetstyle')) { // use imagesetstyle + imageline instead of bugged ImageDashedLine $style = array($color, $color, $color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); imagesetstyle($image, $style); zbx_imageline($image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); } else { imagedashedline($image, $x1, $y1, $x2, $y2, $color); } } elseif ($drawtype == MAP_LINK_DRAWTYPE_DOT && function_exists('imagesetstyle')) { $style = array($color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); imagesetstyle($image, $style); zbx_imageline($image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); } else { zbx_imagealine($image, $x1, $y1, $x2, $y2, $color); } }
/** * Create the image containing $code with a seed of $seed */ function execute($code, $seed) { global $config; srand($seed); mt_srand($seed); // Create image $img = imagecreatetruecolor($this->width, $this->height); // Generate colours $colour = new colour_manager($img, array( 'random' => true, 'min_value' => 60, ), 'hsv'); $scheme = $colour->colour_scheme('background', false); $scheme = $colour->mono_range($scheme, 10, false); shuffle($scheme); $bg_colours = array_splice($scheme, mt_rand(6, 12)); // Generate code characters $characters = $sizes = $bounding_boxes = array(); $width_avail = $this->width - 15; $code_len = strlen($code); $captcha_bitmaps = $this->captcha_bitmaps(); for ($i = 0; $i < $code_len; ++$i) { $characters[$i] = new char_cube3d($captcha_bitmaps, $code[$i]); list($min, $max) = $characters[$i]->range(); $sizes[$i] = mt_rand($min, $max); $box = $characters[$i]->dimensions($sizes[$i]); $width_avail -= ($box[2] - $box[0]); $bounding_boxes[$i] = $box; } // Redistribute leftover x-space $offset = array(); for ($i = 0; $i < $code_len; ++$i) { $denom = ($code_len - $i); $denom = max(1.3, $denom); $offset[$i] = mt_rand(0, (1.5 * $width_avail) / $denom); $width_avail -= $offset[$i]; } if ($config['captcha_gd_x_grid']) { $grid = (int) $config['captcha_gd_x_grid']; for ($y = 0; $y < $this->height; $y += mt_rand($grid - 2, $grid + 2)) { $current_colour = $scheme[array_rand($scheme)]; imageline($img, mt_rand(0,4), mt_rand($y - 3, $y), mt_rand($this->width - 5, $this->width), mt_rand($y - 3, $y), $current_colour); } } if ($config['captcha_gd_y_grid']) { $grid = (int) $config['captcha_gd_y_grid']; for ($x = 0; $x < $this->width; $x += mt_rand($grid - 2, $grid + 2)) { $current_colour = $scheme[array_rand($scheme)]; imagedashedline($img, mt_rand($x -3, $x + 3), mt_rand(0, 4), mt_rand($x -3, $x + 3), mt_rand($this->height - 5, $this->height), $current_colour); } } $xoffset = 5; for ($i = 0; $i < $code_len; ++$i) { $dimm = $bounding_boxes[$i]; $xoffset += ($offset[$i] - $dimm[0]); $yoffset = mt_rand(-$dimm[1], $this->height - $dimm[3]); $characters[$i]->drawchar($sizes[$i], $xoffset, $yoffset, $img, $colour->get_resource('background'), $scheme); $xoffset += $dimm[2]; } if ($config['captcha_gd_foreground_noise']) { $this->noise_line($img, 0, 0, $this->width, $this->height, $colour->get_resource('background'), $scheme, $bg_colours); } // Send image header('Content-Type: image/png'); header('Cache-control: no-cache, no-store'); imagepng($img); imagedestroy($img); }
ImageLine($Image, 41, 260 - $label * $gap, 740 + $negative, 260 - $label * $gap, $ltgrey); } if ($negative > 10) { ImageLine($Image, 40 + $negative, 20, 40 + $negative, 260, $dkgrey); } ImageLine($Image, 50, 20, 50, 260, $dkgrey); ImageLine($Image, 50, 260, 740 + $negative, 260, $dkgrey); // Add quartile lines if (isset($_GET['q1']) and isset($_GET['q2']) and isset($_GET['q3'])) { for ($i = 1; $i <= 3; $i++) { $quartile = round($_GET["q{$i}"], 2); imagedashedline($Image, $quartile * 7 + 40 + $negative, 20, $quartile * 7 + 40 + $negative, 260, $blue); } } imagedashedline($Image, $min_mark * 7 + 38 + $negative, 20, $min_mark * 7 + 38 + $negative, 260, $blue); imagedashedline($Image, $max_mark * 7 + 43 + $negative, 20, $max_mark * 7 + 43 + $negative, 260, $blue); ImageRectangle($Image, round($_GET["q1"], 2) * 7 + 40 + $negative, 1, round($_GET["q3"], 2) * 7 + 40 + $negative, 13, $blue); ImageLine($Image, round($_GET["q2"], 2) * 7 + 40 + $negative, 1, round($_GET["q2"], 2) * 7 + 40 + $negative, 12, $blue); // Median vertical ImageLine($Image, $min_mark * 7 + 38 + $negative, 1, $min_mark * 7 + 38 + $negative, 13, $blue); // Min vertical ImageLine($Image, $min_mark * 7 + 38 + $negative, 7, round($_GET["q1"], 2) * 7 + 40 + $negative, 7, $blue); // Min whisker ImageLine($Image, $max_mark * 7 + 43 + $negative, 1, $max_mark * 7 + 43 + $negative, 13, $blue); // Max vertical ImageLine($Image, $max_mark * 7 + 43 + $negative, 7, round($_GET["q3"], 2) * 7 + 40 + $negative, 7, $blue); // Max whisker for ($i = $scale_start; $i <= 100; $i++) { if (isset($mydata[$i]) and $mydata[$i] > 0) { if ($i < $_GET['pmk']) { ImageFilledRectangle($Image, $i * 7 + 38 + $negative, 260 - $mydata[$i] * $gap, $i * 7 + 43 + $negative, 260, $red);
/** * Adds the measured item to the PDF output. * * @param object reference (!) to the current ezPDF-Object * @param string commaseperated X-Values of polygon / line * @param string commaseperated Y-Values of polygon / line * @param array configuration settings. * * @return void nothing * * @see makeCoordPairs * @see isClosedPolygon * @see makeStrokePointPairs * @see makePolyFromCoord * @see transformForPDF * @see makeCoordPairs * * @author M. Jansen <*****@*****.**>, 2006-05-26 */ function addMeasuredItem($thePDF, $x_value_str, $y_value_str, $theConfArray = array()) { // get global variable: global $legendFilenameUserPolygon; // create legend image: $legend_width = 17; $leg_img = imagecreate($legend_width, $legend_width); // save previous state: $thePDF->saveState(); // save colors for legend: if (!defined("MAP_HAS_USER_POLYGON")) { define("MAP_HAS_USER_POLYGON", "test"); } // get the arrays $theFullArr = makeCoordPairs($x_value_str, $y_value_str); $thePolyArr = makePolyFromCoord($theFullArr); if (isClosedPolygon($theFullArr)) { $isClosed = TRUE; } else { $isClosed = FALSE; } $nr_of_points = count($theFullArr); // is fill option set? // wenn der erste und letzte punkt nicht �bereinstimmen, // so muss in jedem Falle dofill auf 0 gesetzt werden if ($theConfArray['do_fill'] != '' && $isClosed) { $doFill = 1; // which color to use for filling? if (is_array($theConfArray['fill_color']) && $theConfArray['fill_color']['r'] != '' && $theConfArray['fill_color']['g'] != '' && $theConfArray['fill_color']['b'] != '') { $thePDF->setColor($theConfArray['fill_color']['r'], $theConfArray['fill_color']['g'], $theConfArray['fill_color']['b']); $legend_image_fill = $theConfArray['fill_color']['r'] . "," . $theConfArray['fill_color']['g'] . "," . $theConfArray['fill_color']['b']; // color to legend file $bg_color = imagecolorallocate($leg_img, round($theConfArray['fill_color']['r'] * 255), round($theConfArray['fill_color']['g'] * 255), round($theConfArray['fill_color']['b'] * 255)); } else { $thePDF->setColor(0, 0, 0); // color to legend file $bg_color = imagecolorallocate($leg_img, 0, 0, 0); } } else { $doFill = 0; // color to legend file $bg_color = imagecolorallocate($leg_img, -1, -1, -1); } // Do we need to stroke (outline)? if ($theConfArray['do_stroke'] != '') { // which color to use for filling? if (is_array($theConfArray['stroke_color']) && $theConfArray['stroke_color']['r'] != '' && $theConfArray['stroke_color']['g'] != '' && $theConfArray['stroke_color']['b'] != '') { $thePDF->setStrokeColor($theConfArray['stroke_color']['r'], $theConfArray['stroke_color']['g'], $theConfArray['stroke_color']['b']); $thePDF->setLineStyle($theConfArray['line_style']['width'], $theConfArray['line_style']['cap'], $theConfArray['line_style']['join'], $theConfArray['line_style']['dash']); $theStrokePointPairs = makeStrokePointPairs($theFullArr); for ($i = 0; $i < count($theStrokePointPairs); $i++) { $line = $theStrokePointPairs[$i]; if ($i != count($theStrokePointPairs) - 1 || $isClosed) { $thePDF->line($line[0], $line[1], $line[2], $line[3]); $stroke_color_legend_image = imagecolorallocate($leg_img, round($theConfArray['stroke_color']['r'] * 255), round($theConfArray['stroke_color']['g'] * 255), round($theConfArray['stroke_color']['b'] * 255)); if (is_array($theConfArray['line_style']['dash']) && $theConfArray['line_style']['dash'][1] != "" && $theConfArray['line_style']['dash'][1] != 0) { imagedashedline($leg_img, 0, 0, $legend_width - 1, 0, $stroke_color_legend_image); imagedashedline($leg_img, $legend_width - 1, 1, $legend_width - 1, $legend_width - 1, $stroke_color_legend_image); imagedashedline($leg_img, 0, 0, 0, $legend_width - 1, $stroke_color_legend_image); imagedashedline($leg_img, 0, $legend_width - 1, $legend_width - 1, $legend_width - 1, $stroke_color_legend_image); } else { imageline($leg_img, 0, 0, $legend_width - 1, 0, $stroke_color_legend_image); imageline($leg_img, $legend_width - 1, 0, $legend_width - 1, $legend_width - 1, $stroke_color_legend_image); imageline($leg_img, $legend_width - 1, $legend_width - 1, 0, $legend_width - 1, $stroke_color_legend_image); imageline($leg_img, 0, $legend_width - 1, 0, 0, $stroke_color_legend_image); } } } } } $thePDF->polygon($thePolyArr, $nr_of_points, $doFill); // eventually create the file: imagepng($leg_img, $legendFilenameUserPolygon); $thePDF->restoreState(); }
function DisplayPingChart() { // dodajemy tytuł wykresu; $this->title[] = array('align' => 'center', 'color' => 'dimgrey', 'title' => 'od ' . date('Y/m/d H:i', min($this->cdate)) . ' do ' . date('Y/m/d H:i', max($this->cdate))); if (!empty($this->title)) { for ($i = 0; $i < sizeof($this->title); $i++) { if ($this->title[$i]['align'] == 'left') { $x = 4; } elseif ($this->title[$i]['align'] == 'right') { $x = ceil($this->width - strlen($this->title[$i]['title']) * $this->fonttitlewidth - 4); } else { $x = ceil(($this->width - strlen($this->title[$i]['title']) * $this->fonttitlewidth) / 2); } imagestring($this->img, $this->fonttitlesize, $x, $this->chart_y1 + 2, $this->title[$i]['title'], $this->colors[$this->title[$i]['color']]); $this->chart_y1 += $this->fonttitleheight + 4; } $this->chart_y1 += 6; $this->chart_x2 -= 4; $this->CalculateChart(); } //dodajemy napis z prawej strony $this->chart_x2 -= $this->fontlegendwidth + 5; $this->CalculateChart(); $y = ($this->height - strlen('LMS iNET') * $this->fontlegendheight / 2) / 2; imagestringup($this->img, $this->fontlegendsize, $this->width - ($this->fontlegendheight + 3), $this->height - $y, 'LMS iNET', $this->colors['darkgrey']); if ($this->xlegend) { $this->chart_y2 -= 3 * $this->fontlegendheight + 4; $this->calculatechart(); $count = sizeof($this->ptime); if (!empty($count)) { $avg = 0; $licznik = 0; $min = max($this->ptime); for ($i = 0; $i < $count; $i++) { if ($this->ptime[$i] > '0') { $licznik++; $avg += $this->ptime[$i]; if ($this->ptime[$i] < $min) { $min = $this->ptime[$i]; } } } if ($avg != 0) { $avg = $avg / $licznik; } $count--; $last = $this->ptime[$count]; } else { $avg = $min = $max = $last = 0; } unset($count); unset($licznik); $max = max($this->ptime); $string = 'Min: ' . sprintf("%.2f", $min) . ' ms Avg: ' . sprintf("%.2f", $avg) . ' ms Max: ' . sprintf("%.2f", $max) . ' ms Last: ' . sprintf("%.2f", $last) . ' ms'; $x = ($this->width - strlen($string) * $this->fontlegendwidth) / 2; $y = $this->chart_y2 + 2 * $this->fontlegendheight; $this->CalculateChart(); imagestring($this->img, $this->fontlegendsize, $x, $y, $string, $this->colors['dimgrey']); } if ($this->ylegend) { $widthstr = $this->fontlegendwidth * strlen($this->maxy); $this->chart_x1 += $widthstr + 6; $this->chart_y2 -= $this->padding_bottom; $this->CalculateChart(); $step = 20 * $this->maxy / 100; $val = '0.00'; $bar = 20 * $this->chart_height / 100; for ($i = 0; $i < 6; $i++) { $y = $this->chart_y2 - $i * $bar - $this->fontlegendheight / 2 - 2; $tekst = sprintf("%.2f", $val); $tekst = str_replace(',', '.', $tekst); $widthstr = ceil($this->fontlegendwidth * (strlen($this->maxy) - strlen($tekst))) + 4; imagestring($this->img, $this->fontlegendsize, $widthstr, $y, $tekst, $this->colors[$this->ylegendcolor]); $val += $step; } } // rysujemy obszar roboczy $this->backgroundchart(); $this->borderchart(); // rysujemy główną podziałkę if ($this->scale) { // dla osi x (pionowa podziałka) $bar = 5 * $this->chart_width / 100; for ($i = 1; $i < 20; $i++) { $x = $this->chart_x1 + $i * $bar; imageline($this->img, $x, $this->chart_y1, $x, $this->chart_y2, $this->colors[$this->scalecolor]); } // dla osi y (pozioma podziałka) $bar = 10 * $this->chart_height / 100; for ($i = 1; $i < 10; $i++) { $y = $this->chart_y1 + $i * $bar; imageline($this->img, $this->chart_x1, $y, $this->chart_x2, $y, $this->colors[$this->scalecolor]); } } // rysujemy wykres if (!empty($this->columns) && !empty($this->chart_height) && !empty($this->maxy)) { imagesetthickness($this->img, $this->columns_width); if (!empty($this->columns)) { $this->columns_width = $this->chart_width / $this->columns; $y2 = $this->chart_y2; for ($i = 0; $i < $this->columns; $i++) { if ($this->ptime[$i] == '-1') { $column_height = $this->chart_height; } else { $column_height = $this->chart_height / 100 * ($this->ptime[$i] / $this->maxy * 100); } $x1 = $this->chart_x1 + $i * $this->columns_width; $y1 = $this->chart_y2 - $column_height; $x2 = $this->chart_x1 + ($i * $this->columns_width + $this->columns_width); if ($this->ptime[$i] == '-1') { imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->colors['red']); } if ($this->ptime[$i] > '0') { imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->colors['limegreen']); } } } imagesetthickness($this->img, 1); } // rysujemy główną podziałkę if ($this->scale) { $y = $this->chart_y2 + 5; $sizestr = 10 * $this->fontlegendwidth; $countview = ceil($this->chart_width / $sizestr); $countcdate = ceil($this->columns / $countview); for ($i = 0; $i < $countview; $i++) { $x = $this->chart_x2 - $i * $sizestr - 8 * $this->fontlegendwidth; $xs = $this->chart_x2 - $i * $sizestr - 12 * $this->fontlegendwidth; $ind = $this->columns - ($i + 1) * $countcdate; $string1 = date('y-m-d', $this->cdate[$ind]); $string2 = date(' H:i', $this->cdate[$ind]); if ($i < $countview - 1) { imagestring($this->img, $this->fontlegendsize, $xs, $y, $string1, $this->colors['dimgrey']); imagestring($this->img, $this->fontlegendsize, $xs, $y + $this->fontlegendheight, $string2, $this->colors['dimgrey']); imagedashedline($this->img, $x, $this->chart_y1, $x, $this->chart_y2, $this->colors['darkkhaki']); } } // dla osi y (pozioma podziałka) $bar = 10 * $this->chart_height / 100; for ($i = 1; $i < 10; $i++) { $y = $this->chart_y1 + $i * $bar; if ($i % 2) { } else { imagedashedline($this->img, $this->chart_x1, $y, $this->chart_x2, $y, $this->colors['darkkhaki']); } } } header("Content-type: image/png"); imagepng($this->img); }
/** * 为图像增加干扰虚线 * * @params int $num 干扰线条数 */ function addDashed($num) { $width = imagesx($this->hImg); $height = imagesy($this->hImg); for ($i = 0; $i < $num; $i++) { $color = imagecolorallocate($this->hImg, rand(100, 255), rand(100, 255), rand(100, 255)); imagedashedline($this->hImg, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $color); } }
function draw_lines($im, $width, $height) { $line_color = array('red' => 198, 'green' => 189, 'blue' => 165); $linecolor = imagecolorallocate($im, $line_color['red'], $line_color['green'], $line_color['blue']); for ($i = 0; $i <= $height; $i += 10) { imagedashedline($im, 0, $i, $width, $i, $linecolor); } for ($i = 0; $i <= $width; $i += 10) { imagedashedline($im, $i, 0, $i, $height, $linecolor); } return $im; }
private function allocate_diagram_image(array $pngData, $xSpriteMap, $imgSprite, $imgSpriteBW = '') { global $current_user; $font = $this->pmse->getModulePath() . '/img/arial.ttf'; $minX = 10000; $minY = 10000; $maxW = 0; $maxH = 0; $border = 40; foreach ($pngData as $coords) { if ($coords[0] !== 'bpmnFlow') { if ($minX > $coords[1]) { $minX = $coords[1]; } if ($minY > $coords[2]) { $minY = $coords[2]; } if ($maxW < $coords[1] + $coords[3]) { $maxW = $coords[1] + $coords[3]; } if ($maxH < $coords[2] + $coords[4]) { $maxH = $coords[2] + $coords[4]; } } } $x1 = $minX - $border; $y1 = $minY - $border; $x2 = $maxW + $border; $y2 = $maxH + $border; $cWidth = $x2 - $x1; $cHeight = $y2 - $y1; if ($cWidth < 0 && $cHeight < 0) { $cWidth = 100; $cHeight = 100; } $img = imagecreate($cWidth, $cHeight); $white = imagecolorallocate($img, 255, 255, 255); $black = imagecolorallocate($img, 0, 0, 0); $red = imagecolorallocate($img, 255, 0, 0); $red_1 = imagecolorallocate($img, 255, 235, 235); $orange = imagecolorallocate($img, 255, 80, 0); $orange_1 = imagecolorallocate($img, 255, 210, 150); $green = imagecolorallocate($img, 0, 160, 0); $green_1 = imagecolorallocate($img, 195, 220, 195); $gray = imagecolorallocate($img, 0xc0, 0xc0, 0xc0); $aTaskColor = imagecolorallocate($img, 0x33, 0x66, 0x99); $aTaskFillColor = imagecolorallocate($img, 0xf0, 0xf5, 0xfb); $aSubProcessColor = $black; $aSubProcessFillColor = $white; $aNotSupportedColor = imagecolorallocate($img, 0xc0, 0xc0, 0xc0); $aNotSupportedFillColor = $white; foreach ($pngData as $figure) { $element_running = $this->get_element_running($figure[10]); $shape_image = $element_running->in_flow ? $imgSprite : $imgSpriteBW; $aTaskColor = $element_running->in_flow ? imagecolorallocate($img, 0x33, 0x66, 0x99) : imagecolorallocate($img, 0xc0, 0xc0, 0xc0); $aTaskFillColor = $element_running->in_flow ? imagecolorallocate($img, 0xf0, 0xf5, 0xfb) : imagecolorallocate($img, 230, 230, 230); switch ($figure[0]) { case 'bpmnActivity': $X1 = $figure[1] - $x1; $Y1 = $figure[2] - $y1; $X2 = $X1 + $figure[3]; $Y2 = $Y1 + $figure[4]; $properties = explode('_', $figure[7]); $points = array($X1 + 3, $Y1, $X2 - 3, $Y1, $X2, $Y1 + 3, $X2, $Y2 - 3, $X2 - 3, $Y2, $X1 + 3, $Y2, $X1, $Y2 - 3, $X1, $Y1 + 3); $points2 = array($X1 + 5, $Y1 + 2, $X2 - 5, $Y1 + 2, $X2 - 2, $Y1 + 5, $X2 - 2, $Y2 - 5, $X2 - 5, $Y2 - 2, $X1 + 5, $Y2 - 2, $X1 + 2, $Y2 - 5, $X1 + 2, $Y1 + 5); switch ($figure[5]) { case 'TASK': $borderColor = $aTaskColor; $fillColor = $aTaskFillColor; imagesetthickness($img, 2); break; default: $borderColor = $aNotSupportedColor; $fillColor = $aNotSupportedFillColor; imagesetthickness($img, 2); } //CURRENT CASE if ($element_running->running) { $points_active = array($X1 + 3, $Y1, $X2 - 3, $Y1, $X2, $Y1 + 3, $X2, $Y2 - 3, $X2 - 3, $Y2, $X1 + 3, $Y2, $X1, $Y2 - 3, $X1, $Y1 + 3); if ($current_user->id == $element_running->usr_id) { imagefilledpolygon($img, $points, 8, $green_1); imagepolygon($img, $points_active, 8, $green); } else { imagefilledpolygon($img, $points, 8, $red_1); imagepolygon($img, $points_active, 8, $red); } } else { imagefilledpolygon($img, $points, 8, $fillColor); imagepolygon($img, $points, 8, $borderColor); } if ($element_running->terminated) { imagecopymerge($img, $shape_image, $X2 - 15, $figure[2] - $y1 + 3, $xSpriteMap['icon_terminated'][0], $xSpriteMap['icon_terminated'][1], 12, 12, 100); } if ($figure[5] == 'TRANSACTION') { imagepolygon($img, $points2, 8, $borderColor); } if ($figure[5] == 'TASK' || $figure[5] == 'TASKCALLACTIVITY') { if (isset($figure[9]) && $figure[9] != '') { $css = 'scripttask_' . strtolower($figure[9]); $spriteCoords = $xSpriteMap[$css]; imagecopymerge($img, $shape_image, $figure[1] - $x1 - 2, $figure[2] - $y1 - 2, $spriteCoords[0], $spriteCoords[1], 39, 39, 100); } else { $css = 'TASK_' . strtoupper($properties[0]); $spriteCoords = $xSpriteMap[$css]; imagecopymerge($img, $shape_image, $figure[1] - $x1 + 4, $figure[2] - $y1 + 4, $spriteCoords[0], $spriteCoords[1], 12, 12, 100); } } if ($figure[5] == 'TASK' && $properties[1] != 'NONE') { $css = 'LOOP_' . strtoupper($properties[1]); $spriteCoords = $xSpriteMap[$css]; imagecopymerge($img, $shape_image, $figure[1] - $x1 + ($figure[3] - 12) / 2, $figure[2] - $y1 + $figure[4] - 12, $spriteCoords[0], $spriteCoords[1], 12, 12, 100); } if ($figure[5] != 'TASK' && $figure[5] != 'TASKCALLACTIVITY' && $properties[3] == 1) { if ($properties[1] == 'NONE' && $properties[2] == 0) { $spriteCoords = $xSpriteMap['LOOP_NONE']; imagecopymerge($img, $shape_image, $figure[1] - $x1 + ($figure[3] - 12) / 2, $figure[2] - $y1 + $figure[4] - 12, $spriteCoords[0], $spriteCoords[1], 12, 12, 100); } else { $t = 1; if ($properties[2] == 1) { $t++; } if ($properties[1] != 'NONE') { $t++; } if ($t == 3) { $spriteCoords = $xSpriteMap["LOOP_" . $properties[1]]; imagecopymerge($img, $shape_image, $figure[1] - $x1 + ($figure[3] - 36) / 2, $figure[2] - $y1 + $figure[4] - 12, $spriteCoords[0], $spriteCoords[1], 12, 12, 100); $spriteCoords = $xSpriteMap['LOOP_NONE']; imagecopymerge($img, $shape_image, $figure[1] - $x1 + ($figure[3] - 12) / 2, $figure[2] - $y1 + $figure[4] - 12, $spriteCoords[0], $spriteCoords[1], 12, 12, 100); $spriteCoords = $xSpriteMap['ACTIVITY_ADHOC']; imagecopymerge($img, $shape_image, $figure[1] - $x1 + ($figure[3] - 12) / 2 + 13, $figure[2] - $y1 + $figure[4] - 12, $spriteCoords[0], $spriteCoords[1], 12, 12, 100); } else { if ($properties[1] != 'NONE') { $spriteCoords = $xSpriteMap["LOOP_" . $properties[1]]; imagecopymerge($img, $shape_image, $figure[1] - $x1 + ($figure[3] - 12) / 2 + 7, $figure[2] - $y1 + $figure[4] - 12, $spriteCoords[0], $spriteCoords[1], 12, 12, 100); $spriteCoords = $xSpriteMap['LOOP_NONE']; imagecopymerge($img, $shape_image, $figure[1] - $x1 + ($figure[3] - 12) / 2 + 6, $figure[2] - $y1 + $figure[4] - 12, $spriteCoords[0], $spriteCoords[1], 12, 12, 100); } else { //unknow process ?? } } } } //Print Text if (isset($figure[9]) && $figure[9] != '') { $tt = explode('_', $figure[7]); $this->print_text($img, $figure[6], 10, 0, $black, $font, $X1, $Y1, $X2, $Y2, $figure[0], $tt[0]); } else { $this->print_text($img, $figure[6], 10, 0, $black, $font, $X1, $Y1, $X2, $Y2, $figure[0], $figure[5]); } break; case 'bpmnEvent': $X1 = $figure[1] - $x1; $Y1 = $figure[2] - $y1 + $figure[4] - 10; $X2 = $X1 + $figure[3]; $Y2 = $Y1 + $figure[4] + 5; $css = $figure[5]; $marker = $figure[7]; $spriteCoords = $xSpriteMap[$css]; $mk = explode('_', $figure[7]); //CURRENT CASE if (isset($element_running->running) && $element_running->running) { // imageline($img, $X2 + 5 , $figure[2] - $y1, $X2 + 5, $figure[2] - $y1 + $figure[4], $red); // imageline($img, $X2 , $figure[2] - $y1 - 5, $X2 + 5, $figure[2] - $y1, $red); // imageline($img, $X2 + 5 , $figure[2] - $y1 + $figure[4], $X2, $figure[2] - $y1 + $figure[4] + 5, $red); // imagecopymerge ($img, $shape_image, $X2 + 10, $figure[2] - $y1 + (int)(($figure[4]/2)-5) , $xSpriteMap['text_now'][0], $xSpriteMap['text_now'][1], 24, 10, 100); $event_active_filename = $this->pmse->getModulePath() . '/img/event_active.gif'; $event_active = imagecreatefromgif($event_active_filename); if ($mk['1'] == 'TIMER') { imagecopymerge($img, $event_active, $figure[1] - $x1 - 4, $figure[2] - $y1 - 4, 0, 0, $figure[3] + 8, $figure[4] + 8, 100); } else { imagecopymerge($img, $event_active, $figure[1] - $x1 - 4, $figure[2] - $y1 - 4, 0, 41, $figure[3] + 8, $figure[4] + 8, 100); } } else { imagecopymerge($img, $shape_image, $figure[1] - $x1, $figure[2] - $y1, $spriteCoords[0], $spriteCoords[1], $figure[3] + 3, $figure[4] + 3, 100); } if ($marker != 'EMPTY') { //END_CANCELTHROW??? if (isset($xSpriteMap[$marker])) { // patch for an inexistent index // echo '<br>MARKER: <br>    ' . $marker .'<br>'; print_r($xSpriteMap[$marker]) . '<br>'; $spriteCoords2 = $xSpriteMap[$marker]; if (!($element_running->running && $mk[1] == 'TIMER')) { imagecopymerge($img, $shape_image, $figure[1] - $x1, $figure[2] - $y1, $spriteCoords2[0], $spriteCoords2[1], $figure[3], $figure[4], 100); } } } if (isset($element_running->terminated) && $element_running->terminated) { imagecopymerge($img, $shape_image, $X2, $figure[2] - $y1, $xSpriteMap['icon_terminated'][0], $xSpriteMap['icon_terminated'][1], 12, 12, 100); } $this->print_text($img, $figure[6], 10, 0, $black, $font, $X1, $Y1, $X2, $Y2, $figure[0]); break; case 'bpmnGateway': // print_r($figure); echo '<br><br>'; $X1 = $figure[1] - $x1; $Y1 = $figure[2] - $y1 + $figure[4] - 10; $X2 = $X1 + $figure[3]; $Y2 = $Y1 + $figure[4] + 5; $css = $figure[5]; $spriteCoords = $xSpriteMap[$css]; imagecopymerge($img, $shape_image, $figure[1] - $x1, $figure[2] - $y1, $spriteCoords[0], $spriteCoords[1], $figure[3], $figure[4], 100); $this->print_text($img, $figure[6], 10, 0, $black, $font, $X1, $Y1, $X2, $Y2, $figure[0]); break; case 'bpmnArtifact': $xX1 = $figure[1] - $x1; $xY1 = $figure[2] - $y1; $xX2 = $xX1 + $figure[3]; $xY2 = $xY1 + $figure[4]; imagesetthickness($img, 1); if ($figure[6] == 'GROUP') { imagedashedline($img, $xX1, $xY1, $xX2, $xY1, $black); imagedashedline($img, $xX2, $xY1, $xX2, $xY2, $black); imagedashedline($img, $xX2, $xY2, $xX1, $xY2, $black); imagedashedline($img, $xX1, $xY2, $xX1, $xY1, $black); } if ($figure[6] == 'TEXTANNOTATION') { imageline($img, $xX1, $xY1, $xX1, $xY2, $black); imageline($img, $xX1, $xY1, $xX1 + 15, $xY1, $black); imageline($img, $xX1, $xY2, $xX1 + 15, $xY2, $black); } $this->print_text($img, $figure[5], 10, 0, $black, $font, $xX1, $xY1, $xX2, $xY2, $figure[0], $figure[5]); break; //this break wasn't here ... //this break wasn't here ... case 'bpmnFlow': $X1 = $figure[1] - $x1; $Y1 = $figure[2] - $y1; $X2 = $X1 + $figure[3]; $Y2 = $Y1 + $figure[4]; imagesetthickness($img, 1); $lines = json_decode($figure[9]); if ($element_running->in_flow) { $line_color = $black; $shape_image = $imgSprite; } else { $line_color = $gray; $shape_image = $imgSpriteBW; } foreach ($lines as $key => $segment) { // echo '<br>Point'. $key . ': (' . $lines[$key]->x . ', ' . $lines[$key]->y .')'; // echo '<br>Point'. ($key + 1) . ': (' . $lines[$key+1]->x . ', ' . $lines[$key+1]->y .')'; if (isset($lines[$key + 1]) && $lines[$key + 1]->x != '' && $lines[$key + 1]->y != '') { if ($figure[2] == 'MESSAGE' || $figure[2] == 'ASSOCIATION' || $figure[2] == 'DATAASSOCIATION') { imagedashedline($img, $lines[$key]->x - $x1, $lines[$key]->y - $y1, $lines[$key + 1]->x - $x1, $lines[$key + 1]->y - $y1, $line_color); } else { imageline($img, $lines[$key]->x - $x1, $lines[$key]->y - $y1, $lines[$key + 1]->x - $x1, $lines[$key + 1]->y - $y1, $line_color); } if ((int) ((sizeof($lines) - 1) / 2) == $key) { if (isset($element_running->count) && $element_running->count > 1) { $cf = ' (' . $element_running->count . ')'; } else { $cf = ''; } $this->print_text($img, $figure[1] . $cf, 10, 0, $black, $font, $lines[$key]->x - $x1, $lines[$key]->y, $lines[$key + 1]->x - $x1, $lines[$key + 1]->y - $y1); } } } $decorator_width = 11; $decorator_height = 11; //END DECORATOR $colorBackView = imagecolorallocate($img, 24, 124, 220); if ($lines[sizeof($lines) - 1]->x == $lines[sizeof($lines) - 2]->x) { if ($lines[sizeof($lines) - 1]->y < $lines[sizeof($lines) - 2]->y) { $spriteCoords = $xSpriteMap['arrow_target_bottom']; imagecopymerge($img, $shape_image, $lines[sizeof($lines) - 1]->x - (int) ($decorator_width / 2) - $x1, $lines[sizeof($lines) - 1]->y - $y1, $spriteCoords[0], $spriteCoords[1], $decorator_width, $decorator_height, 100); } else { $spriteCoords = $xSpriteMap['arrow_target_top']; imagecopymerge($img, $shape_image, $lines[sizeof($lines) - 1]->x - (int) ($decorator_width / 2) - $x1, $lines[sizeof($lines) - 1]->y - $decorator_height - $y1, $spriteCoords[0], $spriteCoords[1], $decorator_width, $decorator_height, 100); } } elseif ($lines[sizeof($lines) - 1]->y == $lines[sizeof($lines) - 2]->y) { if ($lines[sizeof($lines) - 1]->x < $lines[sizeof($lines) - 2]->x) { $spriteCoords = $xSpriteMap['arrow_target_right']; imagecopymerge($img, $shape_image, $lines[sizeof($lines) - 1]->x - $x1, $lines[sizeof($lines) - 1]->y - (int) ($decorator_height / 2) - $y1, $spriteCoords[0], $spriteCoords[1], $decorator_width, $decorator_height, 100); } else { $spriteCoords = $xSpriteMap['arrow_target_left']; imagecopymerge($img, $shape_image, $lines[sizeof($lines) - 1]->x - $decorator_width - $x1, $lines[sizeof($lines) - 1]->y - (int) ($decorator_height / 2) - $y1, $spriteCoords[0], $spriteCoords[1], $decorator_width, $decorator_height, 100); } } //SOURCE DECORATOR if ($figure[2] === 'DEFAULT' or $figure[2] === 'CONDITIONAL') { if ($figure[2] === 'DEFAULT') { $source_decorator = '_default'; } elseif ($figure[2] === 'CONDITIONAL') { $source_decorator = '_conditional'; } if ($lines[0]->x == $lines[1]->x) { if ($lines[0]->y < $lines[1]->y) { $spriteCoords = $xSpriteMap['arrow' . $source_decorator . '_source_top']; imagecopymerge($img, $shape_image, $lines[0]->x - (int) ($decorator_width / 2) - $x1, $lines[0]->y - $y1, $spriteCoords[0], $spriteCoords[1], $decorator_width, $decorator_height, 100); } else { $spriteCoords = $xSpriteMap['arrow' . $source_decorator . '_source_bottom']; imagecopymerge($img, $shape_image, $lines[0]->x - (int) ($decorator_width / 2) - $x1, $lines[0]->y - $decorator_height - $y1, $spriteCoords[0], $spriteCoords[1], $decorator_width, $decorator_height, 100); } } elseif ($lines[0]->y == $lines[1]->y) { if ($lines[0]->x < $lines[1]->x) { $spriteCoords = $xSpriteMap['arrow' . $source_decorator . '_source_right']; imagecopymerge($img, $shape_image, $lines[0]->x - $x1, $lines[0]->y - (int) ($decorator_height / 2) - $y1, $spriteCoords[0], $spriteCoords[1], $decorator_width, $decorator_height, 100); } else { $spriteCoords = $xSpriteMap['arrow' . $source_decorator . '_source_left']; imagecopymerge($img, $shape_image, $lines[0]->x - $decorator_width - $x1, $lines[0]->y - (int) ($decorator_height / 2) - $y1, $spriteCoords[0], $spriteCoords[1], $decorator_width, $decorator_height, 100); } } } break; } } return $img; }
public function line(array $settings) : InternalGD { $x1 = isset($settings['x1']) ? $settings['x1'] : 0; $y1 = isset($settings['y1']) ? $settings['y1'] : 0; $x2 = isset($settings['x2']) ? $settings['x2'] : 0; $y2 = isset($settings['y2']) ? $settings['y2'] : 0; $rgb = isset($settings['color']) ? $settings['color'] : '0|0|0'; $type = isset($settings['type']) ? $settings['type'] : 'solid'; $type = strtolower($type); if ($type === 'solid') { imageline($this->canvas, $x1, $y1, $x2, $y2, $this->allocate($rgb)); } elseif ($type === 'dashed') { imagedashedline($this->canvas, $x1, $y1, $x2, $y2, $this->allocate($rgb)); } return $this; }
function make_linkFN($children_ha, $im_dest, $position_node) { $background_R = $GLOBALS['background_R']; $background_G = $GLOBALS['background_G']; $background_B = $GLOBALS['background_B']; $foreground_R = $GLOBALS['foreground_R']; $foreground_G = $GLOBALS['foreground_R']; $foreground_B = $GLOBALS['foreground_R ']; $root_dir = $GLOBALS['root_dir']; $layout_template = $GLOBALS['layout_template']; $duplicate_dir_structure = $GLOBALS['duplicate_dir_structure']; $family = $GLOBALS['family']; $debug = $GLOBALS['debug']; $src_x = 0; $src_y = 0; $text_color = ImageColorAllocate($im_dest, $foreground_R, $foreground_G, $foreground_B); $node_from_found = 0; $node_to_found = 0; foreach ($children_ha as $child) { $id_node_from = $child['id_child']; $linked = $child['linked']; if (!empty($linked)) { foreach ($linked as $link) { $id_node_to = $link['id_node_to']; mydebug(__LINE__, __FILE__, array('id_node_to' => $id_node_to, 'id_node_from' => $id_node_from)); foreach ($position_node as $pos) { $id_node = $pos['id_node']; mydebug(__LINE__, __FILE__, array('id_node_from' => $id_node_from, 'id_node_to' => $id_node_to, 'id_node' => $id_node, 'trovato' => $node_from_found)); if ($id_node == $id_node_from and !$node_from_found) { // get position of node from mydebug(__LINE__, __FILE__, $id_node); $bounds = $pos['bounds']; $bounds = explode(",", $bounds); $xa1 = $bounds[0]; $ya1 = $bounds[1]; // left top corner $xa4 = $bounds[2]; $ya4 = $bounds[3]; // right bottom corner $xa2 = $xa4; $ya2 = $ya1; // right top corner $xa3 = $xa1; $ya3 = $ya4; // left bottom corner $node_from_found = 1; } elseif ($id_node == $id_node_to and !$node_to_found) { // get position of node to $node_to_found = 1; $bounds = $pos['bounds']; $bounds = explode(",", $bounds); $xb1 = $bounds[0]; $yb1 = $bounds[1]; // left top corner $xb4 = $bounds[2]; $yb4 = $bounds[3]; // right bottom corner $xb2 = $xb4; $yb2 = $yb1; // right top corner $xb3 = $xb1; $yb3 = $yb4; // left bottom corner } } if ($node_from_found and $node_to_found) { $node_from_found = 0; $node_to_found = 0; // Calcola la distanza tra i punti $min_dist = 10000; $min_array = 0; $distanza_ar = array(); $coordinate_ar = array(); for ($i = 1; $i <= 4; $i++) { $XA = "xa" . $i; $YA = "ya" . $i; for ($o = 1; $o <= 4; $o++) { $XB = "xb" . $o; $YB = "yb" . $o; $distanza_ar[] = round(sqrt(abs(pow(${$XA} - ${$XB}, 2) + pow(${$YA} - ${$YB}, 2)))); $coordinate_ar[] = ${$XA} . "," . ${$YA} . "," . ${$XB} . "," . ${$YB}; } } for ($i = 0; $i <= 15; $i++) { if ($distanza_ar[$i] < $min_dist) { $min_array = $i; $min_dist = $distanza_ar[$i]; # echo "Minore = $min_array, distanza Minore = $min_dist <BR>"; } } $coordinate = $coordinate_ar[$min_array]; $coord_final = explode(",", $coordinate); # echo "$coordinate<BR><BR>"; $x_from = $coord_final[0]; $y_from = $coord_final[1]; $x_to = $coord_final[2]; $y_to = $coord_final[3]; imagedashedline($im_dest, $x_from, $y_from, $x_to, $y_to, $text_color); } } } } return true; }
/** * Draw a line * * @param integer $x1 * @param integer $y1 * @param integer $x2 * @param integer $y2 * @param array $colour * @param float $opacity * @param boolean $dashed * @return $this */ public function line($x1 = 0, $y1 = 0, $x2 = 100, $y2 = 100, $colour = array(0, 0, 0), $opacity = 1.0, $dashed = false) { if ($dashed === true) { imagedashedline($this->img, $x1, $y1, $x2, $y2, imagecolorallocatealpha($this->img, $colour[0], $colour[1], $colour[2], (1 - $opacity) * 127)); } else { imageline($this->img, $x1, $y1, $x2, $y2, imagecolorallocatealpha($this->img, $colour[0], $colour[1], $colour[2], (1 - $opacity) * 127)); } $this->afterUpdate(); return $this; }
/** * Renders the graph to memory * */ public function render() { // Get our max's and min's $asorted = $this->points; sort($asorted, SORT_NUMERIC); $min = $asorted[0]; $max = $asorted[count($asorted) - 1]; // Scale based on how many points we need to shove into 930 pixels of width $x_delta = $this->inside_width / count($this->points); // Scale our y axis to 220 pixels $y_scale_factor = ($max - $min) / $this->inside_height; // Get our Y initial $y_initial = $this->inside_y + $this->inside_height; // Get our scale for finding our points of reference to place our x axis labels $x_label_scale = ceil(count($this->points) / 20); $x_label_points = array(); foreach ($this->points as $x => $y) { if (($x_label_scale == 0 || ($x + 1) % $x_label_scale == 0) && $x != 0) { $x_label_points[] = $x; imagedashedline($this->im, $this->inside_x + $x_delta * $x, 30, $this->inside_x + $x_delta * $x, $y_initial, $this->color(185, 185, 185)); imagefilledellipse($this->im, $this->inside_x + $x_delta * $x, $y_initial - $next_y_scaled + 0.5, 8, 8, $this->color(84, 92, 209)); } // Look ahead to find our next point, if there is one if (!array_key_exists($x + 1, $this->points)) { break; } $next_y = $this->points[$x + 1]; if ($y_scale_factor == 0) { $y_scaled = $next_y_scaled = 0; } else { $y_scaled = ($y - $min) / $y_scale_factor; $next_y_scaled = ($next_y - $min) / $y_scale_factor; } // Draw our line $this->imagelinethick($this->inside_x + $x_delta * $x, $y_initial - $y_scaled, $this->inside_x + $x_delta * ($x + 1), $y_initial - $next_y_scaled, $this->color(84, 92, 209), 3); } // Draw our x labels foreach ($x_label_points as $x) { $label = $this->x_labels[$x]; $text_width = imagefontwidth(2) * strlen($label); $x = $this->inside_x + $x_delta * $x - $text_width / 2; imagestring($this->im, 2, $x, $y_initial + 5, $label, $this->color(0, 0, 0)); } // Draw our bottom label imagestring($this->im, 2, $this->img_width / 2, $y_initial + 25, $this->bottom_label, $this->color(0, 0, 0)); if ($max > 4) { // Draw our y labels for ($i = 1; $i < 4; ++$i) { $y_value = $this->inside_y + $this->inside_height / 4 * $i; imagestring($this->im, 2, 5, $y_value - 7, my_number_format(round($min + ($max - $min) / 4 * (4 - $i))), $this->color(0, 0, 0)); } } imagestring($this->im, 2, 5, $this->inside_y + $this->inside_height - 7, my_number_format($min), $this->color(0, 0, 0)); imagestring($this->im, 2, 5, $this->inside_y - 7, my_number_format($max), $this->color(0, 0, 0)); }
function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '') { /** * Function to create a random color * Note: We aren't using this outside this function so we will sit it inside * @auteur mastercode.nl * @param $type string Mode for the color * @return int **/ function color($type) { switch ($type) { case "bg": $color = rand(224, 255); break; case "text": $color = rand(0, 127); break; case "grid": $color = rand(200, 224); break; default: $color = rand(0, 255); break; } return $color; } $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_size' => '', 'font_path' => '', 'show_grid' => true, 'skew' => true, 'expiration' => 7200); foreach ($defaults as $key => $val) { if (!is_array($data)) { if (!isset(${$key}) or ${$key} == '') { ${$key} = $val; } } else { ${$key} = !isset($data[$key]) ? $val : $data[$key]; } } if ($img_path == '' or $img_url == '') { return FALSE; } if (!@is_dir($img_path)) { return FALSE; } if (!is_really_writable($img_path)) { return FALSE; } if (!extension_loaded('gd')) { return FALSE; } // ----------------------------------- // Select random Font from folder // ----------------------------------- if (is_dir($font_path)) { $handle = opendir($font_path); while (($file = @readdir($handle)) !== false) { if (!in_array($file, array('.', '..')) && substr($file, strlen($file) - 4, 4) == '.ttf') { $fonts[] = $file; } } $font_file = $font_path . DIRECTORY_SEPARATOR . $fonts[array_rand($fonts)]; } else { $font_file = $font_path; } // ----------------------------------- // Remove old images // ----------------------------------- list($usec, $sec) = explode(" ", microtime()); $now = (double) $usec + (double) $sec; $current_dir = @opendir($img_path); while ($filename = @readdir($current_dir)) { if ($filename != "." and $filename != ".." and $filename != "index.html") { $name = str_replace(".png", "", $filename); if ($name + $expiration < $now) { @unlink($img_path . $filename); } } } @closedir($current_dir); // ----------------------------------- // Do we have a "word" yet? // ----------------------------------- if ($word == '') { // No Zero (for user clarity); $pool = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $str = ''; for ($i = 0; $i < 6; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1); } $word = strtoupper($str); } // ----------------------------------- // Length of Word // ----------------------------------- $length = strlen($word); // ----------------------------------- // Create image // ----------------------------------- $im = ImageCreateTruecolor($img_width, $img_height); // ----------------------------------- // Assign colors // ----------------------------------- $bg_color = imagecolorallocate($im, color('bg'), color('bg'), color('bg')); $border_color = imagecolorallocate($im, 153, 102, 102); $text_color = imagecolorallocate($im, color('text'), color('text'), color('text')); $grid_color[] = imagecolorallocate($im, color('grid'), color('grid'), color('grid')); $grid_color[] = $grid_color[0] + 150; $grid_color[] = $grid_color[0] + 180; $grid_color[] = $grid_color[0] + 210; $shadow_color = imagecolorallocate($im, 255, 240, 240); // ----------------------------------- // Create the rectangle // ----------------------------------- ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color); if ($show_grid == TRUE) { // X grid $grid = rand(20, 25); for ($x = 0; $x < $img_width; $x += mt_rand($grid - 2, $grid + 2)) { $current_colour = $grid_color[array_rand($grid_color)]; imagedashedline($im, mt_rand($x - 3, $x + 3), mt_rand(0, 4), mt_rand($x - 3, $x + 3), mt_rand($img_height - 5, $img_height), $current_colour); } // Y grid for ($y = 0; $y < $img_height; $y += mt_rand($grid - 2, $grid + 2)) { $current_colour = $grid_color[array_rand($grid_color)]; imageline($im, mt_rand(0, 4), mt_rand($y - 3, $y), mt_rand($img_width - 5, $img_width), mt_rand($y - 3, $y), $current_colour); } } // ----------------------------------- // Write the text // ----------------------------------- $use_font = ($font_file != '' and file_exists($font_file) and function_exists('imagettftext')) ? TRUE : FALSE; if ($use_font == FALSE) { $font_size = 5; $x = rand(2, $img_width / ($length / 3)); // y isnt used here } else { // Make font proportional to the image size $font_size = !empty($font_size) ? $font_size : mt_rand(18, 25); $x = rand(4, $img_width - ($font_size + ($font_size >> 1)) * $length); // y isnt used here } for ($i = 0; $i < strlen($word); $i++) { if ($use_font == FALSE) { $y = rand(0, $img_height / 2); imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color); $x += $font_size * 2; } else { $letter = substr($word, $i, 1); $less_rotate = array('c', 'N', 'U', 'Z', '7', '6', '9'); //letters that we don't want rotated too much... $angle = $skew == TRUE ? in_array($letter, $less_rotate) ? rand(-5, 5) : rand(-15, 15) : 0; $y = $img_height / 2 + ($font_size >> 1) + ($skew == TRUE ? rand(-9, 9) : 0); $x += $font_size >> 2; imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_file, $letter); $x += $font_size + ($font_size >> 2); } } // ----------------------------------- // Create the border // ----------------------------------- imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $border_color); // ----------------------------------- // Generate the image // ----------------------------------- $img_name = $now . '.png'; ImagePNG($im, $img_path . $img_name); $img = "<img src=\"{$img_url}{$img_name}\" width=\"{$img_width}\" height=\"{$img_height}\" style=\"border:0;\" alt=\" \" />"; ImageDestroy($im); return array('word' => $word, 'time' => $now, 'image' => $img); }
protected function drawElement(&$data, $from, $to, $minX, $maxX, $minY, $maxY, $drawtype, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $axisside) { if (!isset($data->max[$from]) || !isset($data->max[$to])) { return; } $oxy = $this->oxy[$axisside]; $zero = $this->zero[$axisside]; $unit2px = $this->unit2px[$axisside]; //SDI($oxy); $shift_min_from = $shift_min_to = 0; $shift_max_from = $shift_max_to = 0; $shift_avg_from = $shift_avg_to = 0; if (isset($data->shift_min[$from])) { $shift_min_from = $data->shift_min[$from]; } if (isset($data->shift_min[$to])) { $shift_min_to = $data->shift_min[$to]; } if (isset($data->shift_max[$from])) { $shift_max_from = $data->shift_max[$from]; } if (isset($data->shift_max[$to])) { $shift_max_to = $data->shift_max[$to]; } if (isset($data->shift_avg[$from])) { $shift_avg_from = $data->shift_avg[$from]; } if (isset($data->shift_avg[$to])) { $shift_avg_to = $data->shift_avg[$to]; } /**/ $min_from = $data->min[$from] + $shift_min_from; $min_to = $data->min[$to] + $shift_min_to; $max_from = $data->max[$from] + $shift_max_from; $max_to = $data->max[$to] + $shift_max_to; $avg_from = $data->avg[$from] + $shift_avg_from; $avg_to = $data->avg[$to] + $shift_avg_to; $x1 = $from + $this->shiftXleft - 1; $x2 = $to + $this->shiftXleft; $y1min = $zero - ($min_from - $oxy) / $unit2px; $y2min = $zero - ($min_to - $oxy) / $unit2px; //SDI(array($y1min,$zero,$min_from,$oxy,$unit2px)); $y1max = $zero - ($max_from - $oxy) / $unit2px; $y2max = $zero - ($max_to - $oxy) / $unit2px; $y1avg = $zero - ($avg_from - $oxy) / $unit2px; $y2avg = $zero - ($avg_to - $oxy) / $unit2px; //*/ switch ($calc_fnc) { case CALC_FNC_MAX: $y1 = $y1max; $y2 = $y2max; $shift_from = $shift_max_from; $shift_to = $shift_max_to; break; case CALC_FNC_MIN: $y1 = $y1min; $y2 = $y2min; $shift_from = $shift_min_from; $shift_to = $shift_min_to; break; case CALC_FNC_ALL: $a[0] = $x1; $a[1] = $y1max; $a[2] = $x1; $a[3] = $y1min; $a[4] = $x2; $a[5] = $y2min; $a[6] = $x2; $a[7] = $y2max; //SDI('2: '.$x2.' - '.$x1.' : '.$y2min.' - '.$y1min); imagefilledpolygon($this->im, $a, 4, $minmax_color); imageline($this->im, $x1, $y1max, $x2, $y2max, $max_color); imageline($this->im, $x1, $y1min, $x2, $y2min, $min_color); /* don't use break, avg must be drawed in this statement */ // break; /* don't use break, avg must be drawed in this statement */ // break; case CALC_FNC_AVG: /* don't use break, avg must be drawed in this statement */ // break; /* don't use break, avg must be drawed in this statement */ // break; default: $y1 = $y1avg; $y2 = $y2avg; $shift_from = $shift_avg_from; $shift_to = $shift_avg_to; } $shift_from -= $shift_from != 0 ? $oxy : 0; $shift_to -= $shift_to != 0 ? $oxy : 0; $y1_shift = $zero - $shift_from / $unit2px; $y2_shift = $zero - $shift_to / $unit2px; //*/ // Fixes graph out of bounds problem if ($y1 > $this->sizeY + $this->shiftY && $y2 > $this->sizeY + $this->shiftY || $y1 < $this->shiftY && $y2 < $this->shiftY) { return true; } $y_first = !($y1 > $this->sizeY + $this->shiftY || $y1 < $this->shiftY); $y_second = !($y2 > $this->sizeY + $this->shiftY || $y2 < $this->shiftY); if (!$y_first) { $y1 = $y1 > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY; } else { if (!$y_second) { $y2 = $y2 > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY; } } //-------- /* draw main line */ switch ($drawtype) { case GRAPH_ITEM_DRAWTYPE_BOLD_LINE: imageline($this->im, $x1, $y1 + 1, $x2, $y2 + 1, $avg_color); // break; /* don't use break, must be drawed line also */ // break; /* don't use break, must be drawed line also */ case GRAPH_ITEM_DRAWTYPE_LINE: //SDI(array($this->im,$x1,$y1,$x2,$y2,$avg_color)); imageline($this->im, $x1, $y1, $x2, $y2, $avg_color); break; case GRAPH_ITEM_DRAWTYPE_FILLED_REGION: $a[0] = $x1; $a[1] = $y1; $a[2] = $x1; $a[3] = $y1_shift; $a[4] = $x2; $a[5] = $y2_shift; $a[6] = $x2; $a[7] = $y2; //SDI($a); imagefilledpolygon($this->im, $a, 4, $avg_color); // imageline($this->im,$x1,$y1,$x2,$y2,$this->getShadow('333333',50)); break; case GRAPH_ITEM_DRAWTYPE_DOT: imagefilledrectangle($this->im, $x1 - 1, $y1 - 1, $x1 + 1, $y1 + 1, $avg_color); imagefilledrectangle($this->im, $x2 - 1, $y2 - 1, $x2 + 1, $y2 + 1, $avg_color); break; case GRAPH_ITEM_DRAWTYPE_DASHED_LINE: if (function_exists('imagesetstyle')) { /* Use imagesetstyle+imageline instead of bugged imagedashedline */ $style = array($avg_color, $avg_color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); imagesetstyle($this->im, $style); imageline($this->im, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); } else { imagedashedline($this->im, $x1, $y1, $x2, $y2, $avg_color); } break; } }
protected function drawElement(&$data, $from, $to, $minX, $maxX, $minY, $maxY, $drawtype, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $axisside) { if (!isset($data['max'][$from]) || !isset($data['max'][$to])) { return; } $oxy = $this->oxy[$axisside]; $zero = $this->zero[$axisside]; $unit2px = $this->unit2px[$axisside]; $shift_min_from = $shift_min_to = 0; $shift_max_from = $shift_max_to = 0; $shift_avg_from = $shift_avg_to = 0; if (isset($data['shift_min'][$from])) { $shift_min_from = $data['shift_min'][$from]; } if (isset($data['shift_min'][$to])) { $shift_min_to = $data['shift_min'][$to]; } if (isset($data['shift_max'][$from])) { $shift_max_from = $data['shift_max'][$from]; } if (isset($data['shift_max'][$to])) { $shift_max_to = $data['shift_max'][$to]; } if (isset($data['shift_avg'][$from])) { $shift_avg_from = $data['shift_avg'][$from]; } if (isset($data['shift_avg'][$to])) { $shift_avg_to = $data['shift_avg'][$to]; } /**/ $min_from = $data['min'][$from] + $shift_min_from; $min_to = $data['min'][$to] + $shift_min_to; $max_from = $data['max'][$from] + $shift_max_from; $max_to = $data['max'][$to] + $shift_max_to; $avg_from = $data['avg'][$from] + $shift_avg_from; $avg_to = $data['avg'][$to] + $shift_avg_to; $x1 = $from + $this->shiftXleft - 1; $x2 = $to + $this->shiftXleft; $y1min = $zero - ($min_from - $oxy) / $unit2px; $y2min = $zero - ($min_to - $oxy) / $unit2px; $y1max = $zero - ($max_from - $oxy) / $unit2px; $y2max = $zero - ($max_to - $oxy) / $unit2px; $y1avg = $zero - ($avg_from - $oxy) / $unit2px; $y2avg = $zero - ($avg_to - $oxy) / $unit2px; //*/ switch ($calc_fnc) { case CALC_FNC_MAX: $y1 = $y1max; $y2 = $y2max; $shift_from = $shift_max_from; $shift_to = $shift_max_to; break; case CALC_FNC_MIN: $y1 = $y1min; $y2 = $y2min; $shift_from = $shift_min_from; $shift_to = $shift_min_to; break; case CALC_FNC_ALL: // MAX $y1x = $y1max > $this->sizeY + $this->shiftY || $y1max < $this->shiftY; $y2x = $y2max > $this->sizeY + $this->shiftY || $y2max < $this->shiftY; if ($y1x) { $y1max = $y1max > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY; } if ($y2x) { $y2max = $y2max > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY; } //-- // MIN $y1n = $y1min > $this->sizeY + $this->shiftY || $y1min < $this->shiftY; $y2n = $y2min > $this->sizeY + $this->shiftY || $y2min < $this->shiftY; if ($y1n) { $y1min = $y1min > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY; } if ($y2n) { $y2min = $y2min > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY; } //-- $a[0] = $x1; $a[1] = $y1max; $a[2] = $x1; $a[3] = $y1min; $a[4] = $x2; $a[5] = $y2min; $a[6] = $x2; $a[7] = $y2max; // don't use break, avg must be drawed in this statement // don't use break, avg must be drawed in this statement case CALC_FNC_AVG: // don't use break, avg must be drawed in this statement // don't use break, avg must be drawed in this statement default: $y1 = $y1avg; $y2 = $y2avg; $shift_from = $shift_avg_from; $shift_to = $shift_avg_to; } $shift_from -= $shift_from != 0 ? $oxy : 0; $shift_to -= $shift_to != 0 ? $oxy : 0; $y1_shift = $zero - $shift_from / $unit2px; $y2_shift = $zero - $shift_to / $unit2px; //*/ if (!$this->limitToBounds($y1, $y2, $this->shiftY, $this->sizeY, $drawtype)) { return true; } if (!$this->limitToBounds($y1_shift, $y2_shift, $this->shiftY, $this->sizeY, $drawtype)) { return true; } // draw main line switch ($drawtype) { case GRAPH_ITEM_DRAWTYPE_BOLD_LINE: if ($calc_fnc == CALC_FNC_ALL) { imagefilledpolygon($this->im, $a, 4, $minmax_color); if (!$y1x || !$y2x) { imageline($this->im, $x1 + 1, $y1max, $x2 + 1, $y2max, $max_color); imageline($this->im, $x1, $y1max, $x2, $y2max, $max_color); } if (!$y1n || !$y2n) { imageline($this->im, $x1 - 1, $y1min, $x2 - 1, $y2min, $min_color); imageline($this->im, $x1, $y1min, $x2, $y2min, $min_color); } } imageline($this->im, $x1, $y1 + 1, $x2, $y2 + 1, $avg_color); imageline($this->im, $x1, $y1, $x2, $y2, $avg_color); break; case GRAPH_ITEM_DRAWTYPE_LINE: if ($calc_fnc == CALC_FNC_ALL) { imagefilledpolygon($this->im, $a, 4, $minmax_color); if (!$y1x || !$y2x) { imageline($this->im, $x1, $y1max, $x2, $y2max, $max_color); } if (!$y1n || !$y2n) { imageline($this->im, $x1, $y1min, $x2, $y2min, $min_color); } } imageline($this->im, $x1, $y1, $x2, $y2, $avg_color); break; case GRAPH_ITEM_DRAWTYPE_FILLED_REGION: //-- $a[0] = $x1; $a[1] = $y1; $a[2] = $x1; $a[3] = $y1_shift; $a[4] = $x2; $a[5] = $y2_shift; $a[6] = $x2; $a[7] = $y2; imagefilledpolygon($this->im, $a, 4, $avg_color); break; case GRAPH_ITEM_DRAWTYPE_DOT: imagefilledrectangle($this->im, $x1 - 1, $y1 - 1, $x1, $y1, $avg_color); break; case GRAPH_ITEM_DRAWTYPE_BOLD_DOT: imagefilledrectangle($this->im, $x2 - 1, $y2 - 1, $x2 + 1, $y2 + 1, $avg_color); break; case GRAPH_ITEM_DRAWTYPE_DASHED_LINE: if (function_exists('imagesetstyle')) { // Use imagesetstyle+imageline instead of bugged imagedashedline $style = array($avg_color, $avg_color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); imagesetstyle($this->im, $style); imageline($this->im, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); } else { imagedashedline($this->im, $x1, $y1, $x2, $y2, $avg_color); } break; case GRAPH_ITEM_DRAWTYPE_GRADIENT_LINE: ImageLine($this->im, $x1, $y1, $x2, $y2, $avg_color); //draw the initial line ImageLine($this->im, $x1, $y1 - 1, $x2, $y2 - 1, $avg_color); $bitmask = 255; $blue = $avg_color & $bitmask; // $blue_diff = 255 - $blue; $bitmask = $bitmask << 8; $green = ($avg_color & $bitmask) >> 8; // $green_diff = 255 - $green; $bitmask = $bitmask << 8; $red = ($avg_color & $bitmask) >> 16; // $red_diff = 255 - $red; $maxAlpha = 110; $startAlpha = 50; $alphaRatio = $maxAlpha / ($this->sizeY - $startAlpha); $diffX = $x1 - $x2; for ($i = 0; $i <= $diffX; $i++) { $Yincr = $diffX > 0 ? abs($y2 - $y1) / $diffX : 0; $gy = $y1 > $y2 ? $y2 + $Yincr * $i : $y2 - $Yincr * $i; $steps = $this->sizeY + $this->shiftY - $gy + 1; for ($j = 0; $j < $steps; $j++) { if ($gy + $j < $this->shiftY + $startAlpha) { $alpha = 0; } else { $alpha = 127 - abs(127 - $alphaRatio * ($gy + $j - $this->shiftY - $startAlpha)); } $color = imagecolorexactalpha($this->im, $red, $green, $blue, $alpha); imagesetpixel($this->im, $x2 + $i, $gy + $j, $color); } } break; } }
public function line($settings = array()) { if (!is_array($settings)) { Error::set(lang('Error', 'arrayParameter', '1.(settings)')); return $this; } $x1 = isset($settings['x1']) ? $settings['x1'] : 0; $y1 = isset($settings['y1']) ? $settings['y1'] : 0; $x2 = isset($settings['x2']) ? $settings['x2'] : 0; $y2 = isset($settings['y2']) ? $settings['y2'] : 0; $rgb = isset($settings['color']) ? $settings['color'] : '0|0|0'; $type = isset($settings['type']) ? $settings['type'] : 'solid'; $type = strtolower($type); if ($type === 'solid') { imageline($this->canvas, $x1, $y1, $x2, $y2, $this->allocate($rgb)); } elseif ($type === 'dashed') { imagedashedline($this->canvas, $x1, $y1, $x2, $y2, $this->allocate($rgb)); } return $this; }