protected static function circle($params) { $borderColor = isset($params['borderColor']) ? $params['borderColor'] : null; $bgColor = isset($params['bgColor']) ? $params['bgColor'] : null; $bgColorFigure = isset($params['bgColorFigure']) ? $params['bgColorFigure'] : null; $indent = $params['diametr'] / 2 + 1; // Размер картинки с отступами $im = imagecreatetruecolor($params['diametr'], $params['diametr']); // Устанавливаем цвет границ if ($borderColor) { $border = imagecolorallocate($im, $borderColor[0], $borderColor[1], $borderColor[2]); } // Устанавливаем заливку поля if (empty($params['transparent'])) { $bg = imagecolorallocate($im, $bgColor[0], $bgColor[1], $bgColor[2]); } else { $bg = imagecolorallocatealpha($im, 0, 0, 0, 127); } // Устанавливаем заливку круга $bgCircle = imagecolorallocate($im, $bgColorFigure[0], $bgColorFigure[1], $bgColorFigure[2]); imagefill($im, 1, 1, $bg); imagesavealpha($im, TRUE); // Рисуем круг imagefilledellipse($im, $indent - 1, $indent - 1, $params['diametr'] - 1, $params['diametr'] - 1, $bgCircle); if ($borderColor) { imageellipse($im, $indent - 1, $indent - 1, $params['diametr'] - 1, $params['diametr'] - 1, $border); } // Выводим изображение imagepng($im); }
function smart_spam($code) { @putenv('GDFONTPATH=' . realpath('.')); $font = 'FONT.TTF'; // antispam image height $height = 40; // antispam image width $width = 110; $font_size = $height * 0.6; $image = @imagecreate($width, $height); $background_color = @imagecolorallocate($image, 255, 255, 255); $noise_color = @imagecolorallocate($image, 20, 40, 100); /* add image noise */ for ($i = 0; $i < $width * $height / 4; $i++) { @imageellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* render text */ $text_color = @imagecolorallocate($image, 20, 40, 100); @imagettftext($image, $font_size, 0, 7, 29, $text_color, $font, $code) or die('Cannot render TTF text.'); //output image to the browser *//* header('Content-Type: image/png'); @imagepng($image) or die('imagepng error!'); @imagedestroy($image); exit; }
public function ellipse(Point $center, $width, $height, $filled = FALSE, Color $color = NULL) { if (!$center->isInImage($this)) { throw new IllegalArgumentException(); } $filled == TRUE ? imagefilledellipse($this->imageResource, $center->getX(), $center->getY(), $width, $height, $this->prepareColor($color)) : imageellipse($this->imageResource, $center->getX(), $center->getY(), $width, $height, $this->prepareColor($color)); }
public function draw($dimension = 100) { $dimension = $this->reDim($dimension); $Center = $dimension / 2; $ScaleFactor = $dimension / max($this->Sizes); $image = imagecreatetruecolor($dimension, $dimension); imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 244)); for ($i = 0; $i < count($this->Sizes); $i++) { $ArrowDiameter = ceil($dimension / 20); } foreach ($this->Sizes as $key => $value) { $diameter = $value * $ScaleFactor; //$ArrowDiameter=min($diameter,$ArrowDiameter); $color = imagecolorallocate($image, $this->Colors[$key][0], $this->Colors[$key][1], $this->Colors[$key][2]); $bordercolor = imagecolorallocate($image, $this->BorderColors[$key][0], $this->BorderColors[$key][1], $this->BorderColors[$key][2]); imagefilledellipse($image, $Center, $Center, $diameter, $diameter, $color); imageellipse($image, $Center, $Center, $diameter, $diameter, $bordercolor); } //$ArrowDiameter=max($dimension/25, $ArrowDiameter/2); $color = imagecolorallocate($image, 64, 255, 64); foreach ($this->ArrowPos as $pos) { if (preg_match("/^[\\-0-9]*,[\\-0-9]*\$/", $pos)) { list($x, $y) = explode(',', $pos); $x = $dimension / 2 + $x * $dimension / 2000; $y = $dimension / 2 + $y * $dimension / 2000; imagefilledellipse($image, $x, $y, $ArrowDiameter, $ArrowDiameter, $color); imageellipse($image, $x, $y, $ArrowDiameter, $ArrowDiameter, $bordercolor); } } header("Content-type: image/png"); imagepng($image); imagedestroy($image); }
private function _drawLine($image, $x1, $y1, $x2, $y2) { $thick = $this->_thickness->getThickness(); $color = $this->_getDrawColor($image); if ($thick == 1) { return imageline($image, $x1, $y1, $x2, $y2, $color); } if ($this->hasTransparency() && $this->_transparency->getTransparency() != ParamTransparency::$minAlpha) { $t = $thick / 2 - 0.5; if ($x1 == $x2 || $y1 == $y2) { return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color); } $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q $a = $t / sqrt(1 + pow($k, 2)); $points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a)); imagefilledpolygon($image, $points, 4, $color); imagepolygon($image, $points, 4, $color); } else { imagesetthickness($image, $thick); imageline($image, $x1, $y1, $x2, $y2, $color); imagesetthickness($image, 1); imagefilledellipse($image, $x1, $y1, $thick, $thick, $color); imagefilledellipse($image, $x2, $y2, $thick, $thick, $color); imageellipse($image, $x1, $y1, $thick, $thick, $color); imageellipse($image, $x2, $y2, $thick, $thick, $color); } }
function printImage() { // Définition du content-type header("Content-type: image/png"); $grey = imagecolorallocate($this->image, 200, 196, 196); $white = imagecolorallocate($this->image, 255, 255, 255); $black = imagecolorallocate($this->image, 0, 0, 0); imagefilledrectangle($this->image, 0, 0, $this->size, 50, $white); $font = 'agenda__.ttf'; // dessinons quelques eclipses ;) for ($t = 0; $t <= 20; $t++) { imageellipse($this->image, rand(0, $this->size), rand(0, 50), rand(0, 200), rand(0, 200), $grey); } // centrage du texte $maxWord = ($this->size - 30) / 27; $cur_left = strlen($this->text) == $maxWord ? 15 : 15 + ($maxWord - strlen($this->text)) * 27 / 2; for ($t = 0; isset($this->text[$t]); $t++) { $cur_incli = rand(-20, 20); // ombre imagettftext($this->image, 32, $cur_incli, $cur_left, 40, $black, $font, $this->text[$t]); // texte imagettftext($this->image, 32, $cur_incli, $cur_left - 1, 39, $this->colours[array_rand($this->colours)], $font, $this->text[$t]); $cur_left += 27; } imagepng($this->image); imagedestroy($this->image); }
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; }
/** * Draws an ellipse on the handle * * @param GD-object $handle The handle on which the ellipse is drawn * @param Zend_Image_Action_DrawEllipse $ellipseObject The object that with all info */ public function perform($handle, Zend_Image_Action_DrawEllipse $ellipseObject) { // As of ZF2.0 / PHP5.3, this can be made static. if($ellipseObject->filled()){ $color = $ellipseObject->getFillColor()->getRgb(); $alpha = $ellipseObject->getFillAlpha(); }else{ $color = $ellipseObject->getStrokeColor()->getRgb(); $alpha = $ellipseObject->getStrokeAlpha(); } $colorAlphaAlloc = imagecolorallocatealpha($handle->getHandle(), $color['red'], $color['green'], $color['blue'], 127 - $alpha * 1.27); if($ellipseObject->filled()) { imagefilledellipse($handle->getHandle(), $ellipseObject->getLocation()->getX(), $ellipseObject->getLocation()->getY(), $ellipseObject->getWidth(), $ellipseObject->getHeight(), $colorAlphaAlloc); } else { imageellipse($handle->getHandle(), $ellipseObject->getLocation()->getX(), $ellipseObject->getLocation()->getY(), $ellipseObject->getWidth(), $ellipseObject->getHeight(), $colorAlphaAlloc); } }
function drawdot($coords, $tipo, $valor) { global $im, $mapHTML, $inner_text, $linecolor; imageline($im, $coords[0], $coords[1], $coords[2], $coords[3], $linecolor[$tipo]); imageellipse($im, $coords[0], $coords[1], 3, 3, $linecolor); imagestring($im, 1, $coords[0] + 2, $coords[1] + 3, $valor, $inner_text); }
function gerImage() { # Calcular tamanho para caber texto $this->w = $this->numChars * $this->charx + 40; #5px de cada lado, 4px por char # Criar img $this->im = imagecreatetruecolor($this->w, $this->h); #desenhar borda e fundo imagefill($this->im, 0, 0, $this->getColor($this->colBorder)); imagefilledrectangle($this->im, 1, 1, $this->w - 2, $this->h - 2, $this->getColor($this->colBG)); #desenhar circulos for ($i = 1; $i <= $this->numCirculos; $i++) { $randomcolor = imagecolorallocate($this->im, rand(120, 255), rand(120, 255), rand(120, 255)); imageellipse($this->im, rand(0, $this->w - 10), rand(0, $this->h - 3), rand(20, 60), rand(20, 60), $randomcolor); } #escrever texto $ident = 20; for ($i = 0; $i < $this->numChars; $i++) { $char = substr($this->texto, $i, 1); $font = rand(5, 5); $y = round(($this->h - 15) / 4); $col = $this->getColor($this->colTxt); if ($i % 4 == 0) { imagechar($this->im, $font, $ident, $y, $char, $col); } else { imagechar($this->im, $font, $ident, $y + rand(3, 18), $char, $col); } $ident = $ident + $this->charx; } }
/** * Private function for creating a random image. * * This function only works with the GD toolkit. ImageMagick is not supported. */ protected function generateImage($extension = 'png', $min_resolution, $max_resolution) { if ($tmp_file = drupal_tempnam('temporary://', 'imagefield_')) { $destination = $tmp_file . '.' . $extension; file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY); $min = explode('x', $min_resolution); $max = explode('x', $max_resolution); $width = rand((int) $min[0], (int) $max[0]); $height = rand((int) $min[1], (int) $max[1]); // Make an image split into 4 sections with random colors. $im = imagecreate($width, $height); for ($n = 0; $n < 4; $n++) { $color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); $x = $width / 2 * ($n % 2); $y = $height / 2 * (int) ($n >= 2); imagefilledrectangle($im, $x, $y, $x + $width / 2, $y + $height / 2, $color); } // Make a perfect circle in the image middle. $color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); $smaller_dimension = min($width, $height); $smaller_dimension = $smaller_dimension % 2 ? $smaller_dimension : $smaller_dimension; imageellipse($im, $width / 2, $height / 2, $smaller_dimension, $smaller_dimension, $color); $save_function = 'image' . ($extension == 'jpg' ? 'jpeg' : $extension); $save_function($im, drupal_realpath($destination)); return $destination; } }
public function generate() { foreach ($this->__shapes as $shape) { $type = array_shift($shape); $color = array_shift($shape); $color = $this->_owner->imagecolorallocate(!isset($color) || is_null($color) ? $this->__base_color : $color, $this->__base_alpha); switch ($type) { case self::LINE: imageline($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color); break; case self::RECTANGLE: imagerectangle($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color); break; case self::FILLED_RECTANGLE: imagefilledrectangle($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color); break; case self::ELLIPSE: imageellipse($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color); break; case self::FILLED_ELLIPSE: imagefilledellipse($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color); break; case self::SPIRAL: $angle = $r = 0; while ($r <= $shape[2]) { imagearc($this->_owner->image, $shape[0], $shape[1], $r, $r, $angle - $shape[3], $angle, $color); $angle += $shape[3]; $r++; } break; } } return true; }
function store_map($im, $data, $shape, $row, $col, $x, $y) { static $color = NULL; if (!isset($color)) { $color = imagecolorallocate($im, 255, 0, 0); } imageellipse($im, $x, $y, 12, 12, $color); }
function store_map($im, $passthru, $shape, $row, $col, $xc, $yc, $diam) { static $color = NULL; if (!isset($color)) { $color = imagecolorallocate($im, 255, 0, 0); } imageellipse($im, $xc, $yc, $diam, $diam, $color); }
/** * Draw ellipse instance on given image * * @param Image $image * @param integer $x * @param integer $y * @return boolean */ public function applyToImage(Image $image, $x = 0, $y = 0) { $background = new Color($this->background); imagefilledellipse($image->getCore(), $x, $y, $this->width, $this->height, $background->getInt()); if ($this->hasBorder()) { $border_color = new Color($this->border_color); imagesetthickness($image->getCore(), $this->border_width); imageellipse($image->getCore(), $x, $y, $this->width, $this->height, $border_color->getInt()); } return true; }
function drawdot($coords, $tipo, $valor, $im, $linecolor) { $inner_text = $linecolor[$tipo]; // imagecolorallocate ( $im, 255, 255, 255 ); imageline($im, $coords[0], $coords[1], $coords[2], $coords[3], $linecolor[$tipo]); imageellipse($im, $coords[0], $coords[1], 3, 3, $linecolor); if ($valor == 0) { $valor = ""; } imagestring($im, 3, $coords[0] + 8, $coords[1] - 10, $valor, $inner_text); }
public function drawDots($vImage, $vColor, $iPosX = 0, $iPosY = false, $iDotSize = 1) { if ($iPosY === false) { $iPosY = imagesy($vImage); } $vBorderColor = imagecolorallocate($vImage, 0, 0, 0); foreach ($this->aCoords as $x => $y) { imagefilledellipse($vImage, $iPosX + round($x), $iPosY - round($y), $iDotSize, $iDotSize, $vColor); imageellipse($vImage, $iPosX + round($x), $iPosY - round($y), $iDotSize, $iDotSize, $vBorderColor); } }
public function generateImage() { $this->securityCode = $this->simpleRandString($this->codeLength); $img_path = dirname(__FILE__) . "/../../web/uploads/"; if (!is_writable($img_path) && !is_dir($img_path)) { $error = "The image path {$img_path} does not appear to be writable or the folder does not exist. Please verify your settings"; throw new Exception($error); } $this->img = imagecreatefromjpeg($img_path . $this->imageFile); $img_size = getimagesize($img_path . $this->imageFile); foreach ($this->fontColor as $fcolor) { $color[] = imagecolorallocate($this->img, hexdec(substr($fcolor, 1, 2)), hexdec(substr($fcolor, 3, 2)), hexdec(substr($fcolor, 5, 2))); } $line = imagecolorallocate($this->img, 255, 255, 255); $line2 = imagecolorallocate($this->img, 200, 200, 200); $fw = imagefontwidth($this->fontSize) + 3; $fh = imagefontheight($this->fontSize); // create a new string with a blank space between each letter so it looks better $newstr = ""; for ($i = 0; $i < strlen($this->securityCode); $i++) { $newstr .= $this->securityCode[$i] . " "; } // remove the trailing blank $newstr = trim($newstr); // center the string $x = ($img_size[0] - strlen($newstr) * $fw) / 2; $font[0] = '/usr/share/fonts/truetype/msttcorefonts/arial.ttf'; $font[1] = '/usr/share/fonts/truetype/msttcorefonts/arial.ttf'; $font[2] = '/usr/share/fonts/truetype/msttcorefonts/arial.ttf'; // create random lines over text for ($i = 0; $i < 3; $i++) { $s_x = rand(40, 180); $s_y = rand(5, 35); $e_x = rand($s_x - 50, $s_x + 50); $e_y = rand(5, 35); $c = rand(0, count($color) - 1); imageline($this->img, $s_x, $s_y, $e_x, $e_y, $color[$c]); } // random bg ellipses imageellipse($this->img, $s_x, $s_y, $e_x, $e_y, $line); imageellipse($this->img, $e_x, $e_y, $s_x, $s_y, $line2); // output each character at a random height and standard horizontal spacing for ($i = 0; $i < strlen($newstr); $i++) { $hz = mt_rand(10, $img_size[1] - $fh - 5); // randomize rotation $rotate = rand(-35, 35); // randomize font size $this->fontSize = rand(14, 18); // radomize color $c = rand(0, count($color) - 1); // imagechar( $this->img, $this->fontSize, $x + ($fw*$i), $hz, $newstr[$i], $color); imagettftext($this->img, $this->fontSize, $rotate, $x + $fw * $i, $hz + 12, $color[0], $font[$c], $newstr[$i]); } }
function view_image($id = null) { if (is_numeric($id)) { $question = $this->Question->findById($id); $line_count = 0; // array of lines $question_text = array(); // Other kinds of newlines causing problems. $question['Question']['question'] = str_replace(array("\r", "\r\n", "\n"), '\\n', $question['Question']['question']); $question_wrapped = wordwrap(strip_tags(QH_urldecode($question['Question']['question'])), $this->number_of_characters, '\\n', true); $question_text = array_merge($question_text, explode('\\n', $question_wrapped)); $line_count += count($question_text); $answers = Set::combine($question['Answer'], '{n}.order', '{n}.answer'); $answer_text = array(); foreach ($answers as $answer) { $answer_wrapped = wordwrap(strip_tags($answer), $this->number_of_characters - 4, '\\n', true); $line_array = explode('\\n', $answer_wrapped); $answer_text[] = $line_array; $line_count += count($line_array); } $box_height = $this->padding * 2 + $this->line_height * $line_count; $box_width = $this->padding * 2 + $this->number_of_characters * $this->character_width; $image = imagecreatetruecolor($box_width, $box_height); $background = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $background); $black = imagecolorallocate($image, 0, 0, 0); imagerectangle($image, 0, 0, $box_width - 1, $box_height - 1, $black); $y = $this->padding + $this->character_height; foreach ($question_text as $line) { imagettftext($image, $this->font_size, 0, $this->padding, $y, $black, APP . 'Lib/unifont_5.1.20080907.ttf', html_entity_decode($line)); // h_e_d for preventing in the image... sometimes. Not clear on that, but // this fixed #206. $y += $this->line_height; } foreach ($answer_text as $order => $answer) { if ($order == $question['Question']['correct_answer']) { imagefilledellipse($image, $this->character_width * 3, $y - $this->character_height / 2, 8, 8, $black); } else { imageellipse($image, $this->character_width * 3, $y - $this->character_height / 2, 8, 8, $black); } foreach ($answer as $answer_line) { $answer_line = ' ' . $answer_line; imagettftext($image, $this->font_size, 0, $this->padding, $y, $black, APP . 'Lib/unifont_5.1.20080907.ttf', $answer_line); $y += $this->line_height; } } $this->layout = 'image'; header("Content-type: image/png"); imagepng($image); imagedestroy($image); $this->autoRender = false; } }
function write_number($x, $y, $n) { global $im, $fg_color, $font_size, $font; if (!($box = imagettftext($im, $font_size, 0, $x, $y, $fg_color, $font, $n))) { die("Error drawing text"); } $el_w = $box[2] - $box[0] + $font_size; $el_h = $box[1] - $box[7] + $font_size / 2; $el_x = ($box[0] + $box[2]) / 2; $el_y = ($box[1] + $box[7]) / 2; imageellipse($im, $el_x, $el_y, $el_w, $el_h, $fg_color); return array($el_x, $el_y, $el_w, $el_h); }
/** * Generowanie tła * * @access public * @param Image_Captcha $image obiekt obrazu * @return void */ public function render(Image_Captcha $image) { $pts = array(); for ($i = 0; $i < round($image->imageWidth() / 1.5); $i++) { $x = rand(0, $image->imageWidth()); $y = rand(0, $image->imageHeight()); if (!in_array($x . '_' . $y, $pts)) { imageellipse($image->imageResource(), $x, $y, rand(2, 7), rand(3, 6), $this->_color(is_array($this->color) ? $this->color[array_rand($this->color)] : $this->color, $image->imageResource())); $pts[] = $x . '_' . $y; } else { $i--; } } }
function Draw($text) { $font = dirname(__FILE__) . "/captcha/font.ttf"; $fontSize = 20; $width = ($fontSize - 5) * strlen($text) + 40; $height = $fontSize + 30; $img = imagecreatetruecolor($width, $height); imagealphablending($img, true); imagesavealpha($img, true); $r = mt_rand(20, 235); $b = mt_rand(20, 235); $g = mt_rand(20, 235); $bgcolor = imagecolorallocatealpha($img, $r, $g, $b, 0); imagefill($img, 1, 1, $bgcolor); $ex = mt_rand(15, 20); if (mt_rand(0, 1)) { $ex = -$ex; } $b += $ex; $r += $ex; $g += $ex; $color = imagecolorallocate($img, $r, $b, $g); $text = explode(" ", $text); $sumWidth = 0; $r -= 2 * ex; $b -= 2 * ex; $g -= 2 * ex; $elcolor = imagecolorallocatealpha($img, $r, $g, $b, 20); $ellipseWidth = mt_rand(30, $width - 50); $ellipsePosX = mt_rand($ellipseWidth, $width - $ellipseWidth); $ellipseHeight = mt_rand(10, 40); $ellipsePosY = mt_rand($ellipseHeight, $height - $ellipseHeight); imageellipse($img, $ellipsePosX, $ellipsePosY, $ellipseWidth, $ellipseHeight, $elcolor); imagefill($img, 20, 30, $elcolor); for ($i = 0; $i < count($text); ++$i) { imagettftext($img, $fontSize, mt_rand(-5, 5), 10 + ($fontSize - 8) * $sumWidth + 20 * $i, $fontSize + mt_rand(-10, 10) + 10, $color, $font, $text[$i]); $sumWidth += strlen($text[$i]); } if (imageistruecolor($img)) { header("content-type: image/png"); echo imagepng($img); } exit; }
/** * TODO: Anti-aliased curves * @param ImageInterface $image * @return ImageInterface */ public function draw($image) { list($x, $y) = $this->pos; $left = $x + $this->width / 2; $top = $y + $this->height / 2; if (null !== $this->fillColor) { list($r, $g, $b, $alpha) = $this->fillColor->getRgba(); $fillColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha)); imagefilledellipse($image->getCore(), $left, $top, $this->width, $this->height, $fillColorResource); } // Create borders. It will be placed on top of the filled ellipse (if present) if (0 < $this->getBorderSize() and null !== $this->borderColor) { // With border > 0 AND borderColor !== null list($r, $g, $b, $alpha) = $this->borderColor->getRgba(); $borderColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha)); imageellipse($image->getCore(), $left, $top, $this->width, $this->height, $borderColorResource); } return $image; }
static function createImageFleche($windRosaceImg, $spot) { $cercleColor = imagecolorallocate($windRosaceImg, 103, 113, 121); // Cercle imageellipse($windRosaceImg, LargeurImg / 2, HauteurImg / 2, 2 * RayonCercle, 2 * RayonCercle, $cercleColor); //on créé un cercle $listOrientation = $spot->getWindOrientation(); $moveArray = RosaceWindManage::getMoveArray(); $colorArray = RosaceWindManage::getColorArray($windRosaceImg); foreach ($listOrientation as $orientation) { try { $points = $moveArray[$orientation->getOrientation()]['points']; $angle = $orientation->getOrientationDeg(); $couleur = $colorArray[$orientation->getState()]; imagefilledpolygon($windRosaceImg, RosaceWindManage::translate_poly($points, $angle, LargeurImg / 2, HauteurImg / 2, 0, 0), 8, $couleur); } catch (\Exception $e) { } } }
/** * Ellipse <ellipse> * * cx, cy - center point * rx - horizontal radius * ry - vertical radius * * @param SimpleXMLElement $element * @param Resource $image Image identifier */ public function ellipse(SimpleXMLElement $element, $image) { $attributes = $this->attributesToArray($element); if (isset($attributes['r'])) { $attributes['rx'] = $attributes['ry'] = $attributes['r']; } if (!empty($attributes['fill'])) { imagefilledellipse($image, $attributes['cx'], $attributes['cy'], $attributes['rx'] * 2, $attributes['ry'] * 2, $this->color->allocate($attributes['fill'], $image, $this->getOpacity($attributes))); } if (!empty($attributes['stroke'])) { if (empty($attributes['stroke-width'])) { $attributes['stroke-width'] = 1; } //bug in PHP doesn't allow use imagesetthickness for ($i = 0; $i <= ceil($attributes['stroke-width']); $i++) { imageellipse($image, $attributes['cx'], $attributes['cy'], $attributes['rx'] * 2 - $i, $attributes['ry'] * 2 - $i, $this->color->allocate($attributes['stroke'], $image, $this->getOpacity($attributes, 'stroke'))); } } }
function draw() { header("Content-type: image/" . $this->format); $this->image = imageCreate($this->x, $this->y); $transparrent = ImageColorAllocate($this->image, 254, 254, 254); imagecolortransparent($this->image, $transparrent); $black = ImageColorAllocate($this->image, 0, 0, 0); $white = ImageColorAllocate($this->image, 255, 255, 255); ImageFill($this->image, 0, 0, $transparrent); //Shadow imagefilledellipse($this->image, $this->x / 2 + 5, $this->y / 2 + 5, $this->x - 20, $this->y - 20, $black); //Main Circle imagefilledellipse($this->image, $this->x / 2, $this->y / 2, $this->x - 20, $this->y - 20, $white); //Inner Ring imageellipse($this->image, $this->x / 2, $this->y / 2, $this->x - 20, $this->y - 20, $black); //Needle imagefilledrectangle($this->image, $this->x / 2 - 2, 30, $this->x / 2 + 2, $this->y / 2, $black); //Center Pin imagefilledellipse($this->image, $this->x / 2, $this->y / 2, 10, 10, $black); ImagePNG($this->image); ImageDestroy($this->image); }
/** * Captcha constructor. */ function __construct() { for ($i = 0; $i < $this->CAPTCHA_NUMCHARS; $i++) { $this->pass_phrase .= chr(mt_rand(97, 122)); } $img = imagecreatetruecolor($this->CAPTCHA_WIDTH, $this->CAPTCHA_HEIGHT); // $text_color = imagecolorallocate($img, 0, 0, 0); $graphic_color = imagecolorallocate($img, 210, 210, 230); $pixel_color = imagecolorallocate($img, 183, 51, 122); $elipse_color = imagecolorallocate($img, 110, 210, 230); $bg_color = imagecolorallocate($img, 51, 122, 183); imagefilledrectangle($img, 0, 0, $this->CAPTCHA_WIDTH, $this->CAPTCHA_HEIGHT, $bg_color); for ($i = 0; $i < 20; $i++) { imagesetpixel($img, mt_rand() % $this->CAPTCHA_WIDTH, mt_rand() % $this->CAPTCHA_HEIGHT, $pixel_color); } for ($i = 0; $i < 3; $i++) { imageline($img, 0, mt_rand() % $this->CAPTCHA_HEIGHT, $this->CAPTCHA_WIDTH, mt_rand() % $this->CAPTCHA_HEIGHT, $graphic_color); } imageellipse($img, $this->CAPTCHA_WIDTH / 2, $this->CAPTCHA_HEIGHT / 2, $this->CAPTCHA_WIDTH, $this->CAPTCHA_HEIGHT, $elipse_color); imagettftext($img, 24, 0, 5, $this->CAPTCHA_HEIGHT - 7, $pixel_color, 'font/NovaMono.ttf', $this->pass_phrase); $this->img = $img; }
function annotate_plot($img, $plot) { global $best_index, $best_sales, $worst_index, $worst_sales; # Allocate our own colors, rather than poking into the PHPlot object: $red = imagecolorresolve($img, 255, 0, 0); $green = imagecolorresolve($img, 0, 216, 0); # Get the pixel coordinates of the data points for the best and worst: list($best_x, $best_y) = $plot->GetDeviceXY($best_index, $best_sales); list($worst_x, $worst_y) = $plot->GetDeviceXY($worst_index, $worst_sales); # Draw ellipses centered on those two points: imageellipse($img, $best_x, $best_y, 50, 20, $green); imageellipse($img, $worst_x, $worst_y, 50, 20, $red); # Place some text above the points: $font = '3'; $fh = imagefontheight($font); $fw = imagefontwidth($font); imagestring($img, $font, $best_x - $fw * 4, $best_y - $fh - 10, 'Good Job!', $green); # We can also use the PHPlot internal function for text. # It does the center/bottom alignment calculations for us. # Specify the font argument as NULL or '' to use the generic one. $plot->DrawText('', 0, $worst_x, $worst_y - 10, $red, 'Bad News!', 'center', 'bottom'); }
protected function drawLegend() { $leftXShift = 20; $units = array('left' => 0, 'right' => 0); $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + $this->legendOffsetY); $legend->color = $this->getColor($this->graphtheme['textcolor'], 0); $legend->rowheight = 14; $legend->fontsize = 9; $row = array(array('text' => ''), array('text' => ''), array('text' => S_LST_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_MIN_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_AVG_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_MAX_SMALL, 'align' => 1, 'fontsize' => 9)); $legend->addRow($row); $colNum = $legend->getNumRows(); $i = $this->type == GRAPH_TYPE_STACKED ? $this->num - 1 : 0; while ($i >= 0 && $i < $this->num) { if ($this->items[$i]['calc_type'] == GRAPH_ITEM_AGGREGATED) { $fnc_name = 'agr(' . $this->items[$i]['periods_cnt'] . ')'; $color = $this->getColor('HistoryMinMax'); } else { $color = $this->getColor($this->items[$i]['color'], GRAPH_STACKED_ALFA); switch ($this->items[$i]['calc_fnc']) { case CALC_FNC_MIN: $fnc_name = S_MIN_SMALL; break; case CALC_FNC_MAX: $fnc_name = S_MAX_SMALL; break; case CALC_FNC_ALL: $fnc_name = S_ALL_SMALL; break; case CALC_FNC_AVG: default: $fnc_name = S_AVG_SMALL; } } $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']]; if ($this->itemsHost) { $item_caption = $this->items[$i]['description']; } else { $item_caption = $this->items[$i]['host'] . ': ' . $this->items[$i]['description']; } if (isset($data) && isset($data['min'])) { if ($this->items[$i]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) { $units['left'] = $this->items[$i]['units']; } else { $units['right'] = $this->items[$i]['units']; } $legend->addCell($colNum, array('text' => $item_caption)); $legend->addCell($colNum, array('text' => '[' . $fnc_name . ']')); $legend->addCell($colNum, array('text' => convert_units($this->getLastValue($i), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2)); $legend->addCell($colNum, array('text' => convert_units(min($data['min']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2)); $legend->addCell($colNum, array('text' => convert_units($data['avg_orig'], $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2)); $legend->addCell($colNum, array('text' => convert_units(max($data['max']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2)); } else { $legend->addCell($colNum, array('text' => $item_caption)); $legend->addCell($colNum, array('text' => '[ ' . S_NO_DATA_SMALL . ' ]')); } imagefilledrectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $color); imagerectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $this->getColor('Black')); $colNum++; if ($this->type == GRAPH_TYPE_STACKED) { $i--; } else { $i++; } } $legend->draw(); // if graph is small, we are not drawing percent line and trigger legends if ($this->sizeY < ZBX_GRAPH_LEGEND_HEIGHT) { return true; } $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY); $legend->color = $this->getColor($this->graphtheme['textcolor'], 0); $legend->rowheight = 14; $legend->fontsize = 9; // Draw percentile if ($this->type == GRAPH_TYPE_NORMAL) { foreach ($this->percentile as $side => $percentile) { if ($percentile['percent'] > 0 && $percentile['value']) { $percentile['percent'] = (double) $percentile['percent']; $legend->addCell($colNum, array('text' => $percentile['percent'] . 'th percentile: ' . convert_units($percentile['value'], $units[$side]) . ' (' . $side . ')', ITEM_CONVERT_NO_UNITS)); if ($side == 'left') { $color = $this->graphtheme['leftpercentilecolor']; } else { $color = $this->graphtheme['rightpercentilecolor']; } imagefilledpolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10), 3, $this->getColor($color)); imagepolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10), 3, $this->getColor('Black No Alpha')); $colNum++; } } } $legend->draw(); $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY + 5); $legend->color = $this->getColor($this->graphtheme['textcolor'], 0); $legend->rowheight = 14; $legend->fontsize = 9; // Draw triggers foreach ($this->triggers as $trigger) { imagefilledellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, 10, 10, $this->getColor($trigger['color'])); imageellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, 10, 10, $this->getColor('Black No Alpha')); $legend->addRow(array(array('text' => $trigger['description']), array('text' => $trigger['constant']))); $colNum++; } $legend->draw(); }
function drawMapHighligts(&$im, $map, $mapInfo) { $selements = $map['selements']; foreach ($selements as $selementId => $selement) { if (isset($selement['elementsubtype']) && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS) { continue; } $elementInfo = $mapInfo[$selementId]; $img = get_png_by_selement($elementInfo); $iconX = imagesx($img); $iconY = imagesy($img); if ($map['highlight'] % 2 == SYSMAP_HIGHLIGHT_ON) { $hl_color = null; $st_color = null; if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_ON) { $hl_color = hex2rgb(getSeverityColor($elementInfo['priority'])); } if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_MAINTENANCE) { $st_color = hex2rgb('FF9933'); } if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_DISABLED) { $st_color = hex2rgb('EEEEEE'); } $mainProblems = array(SYSMAP_ELEMENT_TYPE_HOST_GROUP => 1, SYSMAP_ELEMENT_TYPE_MAP => 1); if (isset($mainProblems[$selement['elementtype']])) { if (!is_null($hl_color)) { $st_color = null; } } elseif (!is_null($st_color)) { $hl_color = null; } if (!is_null($st_color)) { $r = $st_color[0]; $g = $st_color[1]; $b = $st_color[2]; imagefilledrectangle($im, $selement['x'] - 2, $selement['y'] - 2, $selement['x'] + $iconX + 2, $selement['y'] + $iconY + 2, imagecolorallocatealpha($im, $r, $g, $b, 0)); // shadow imagerectangle($im, $selement['x'] - 2 - 1, $selement['y'] - 2 - 1, $selement['x'] + $iconX + 2 + 1, $selement['y'] + $iconY + 2 + 1, imagecolorallocate($im, 120, 120, 120)); imagerectangle($im, $selement['x'] - 2 - 2, $selement['y'] - 2 - 2, $selement['x'] + $iconX + 2 + 2, $selement['y'] + $iconY + 2 + 2, imagecolorallocate($im, 220, 220, 220)); } if (!is_null($hl_color)) { $r = $hl_color[0]; $g = $hl_color[1]; $b = $hl_color[2]; imagefilledellipse($im, $selement['x'] + $iconX / 2, $selement['y'] + $iconY / 2, $iconX + 20, $iconX + 20, imagecolorallocatealpha($im, $r, $g, $b, 0)); imageellipse($im, $selement['x'] + $iconX / 2, $selement['y'] + $iconY / 2, $iconX + 20 + 1, $iconX + 20 + 1, imagecolorallocate($im, 120, 120, 120)); $config = select_config(); if (isset($elementInfo['ack']) && $elementInfo['ack'] && $config['event_ack_enable']) { imagesetthickness($im, 5); imagearc($im, $selement['x'] + $iconX / 2, $selement['y'] + $iconY / 2, $iconX + 20 - 3, $iconX + 20 - 3, 0, 359, imagecolorallocate($im, 50, 150, 50)); imagesetthickness($im, 1); } } } } }