public function drawPolygon(Image_3D_Polygon $polygon) { // Get points $points = $polygon->getPoints(); $coords = array(); foreach ($points as $point) { $coords = array_merge($coords, $point->getScreenCoordinates()); } $coordCount = (int) (count($coords) / 2); if (true) { imageFilledPolygon($this->_image, $coords, $coordCount, $this->_getColor($polygon->getColor())); } else { imagePolygon($this->_image, $coords, $coordCount, $this->_getColor($polygon->getColor())); } }
function make_img($content) { $timage = array(strlen($content) * 20 + 10, 28); // array(largeur, hauteur) de l'image; ici la largeur est fonction du nombre de lettre du contenu, on peut bien sur mettre une largeur fixe. $content = preg_replace('/(\\w)/', '\\1 ', $content); // laisse plus d'espace entre les lettres $image = imagecreatetruecolor($timage[0], $timage[1]); // création de l'image // definition des couleurs $fond = imageColorAllocate($image, 240, 255, 240); $grey = imageColorAllocate($image, 210, 210, 210); $text_color = imageColorAllocate($image, rand(0, 100), rand(0, 50), rand(0, 60)); imageFill($image, 0, 0, $fond); // on remplit l'image de blanc //On remplit l'image avec des polygones for ($i = 0, $imax = mt_rand(3, 5); $i < $imax; $i++) { $x = mt_rand(3, 10); $poly = array(); for ($j = 0; $j < $x; $j++) { $poly[] = mt_rand(0, $timage[0]); $poly[] = mt_rand(0, $timage[1]); } imageFilledPolygon($image, $poly, $x, imageColorAllocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255))); } // Création des pixels gris for ($i = 0; $i < $timage[0] * $timage[1] / rand(15, 18); $i++) { imageSetPixel($image, rand(0, $timage[0]), rand(0, $timage[1]), $grey); } // affichage du texte demandé; on le centre en hauteur et largeur (à peu près ^^") //imageString($image, 5, ceil($timage[0]-strlen($content)*8)/2, ceil($timage[1]/2)-9, $content, $text_color); $longueur_chaine = strlen($content); for ($ch = 0; $ch < $longueur_chaine; $ch++) { imagettftext($image, 18, mt_rand(-30, 30), 10 * ($ch + 1), mt_rand(18, 20), $text_color, 'res/georgia.ttf', $content[$ch]); } $type = function_exists('imageJpeg') ? 'jpeg' : 'png'; @header('Content-Type: image/' . $type); @header('Cache-control: no-cache, no-store'); $type == 'png' ? imagePng($image) : imageJpeg($image); ImageDestroy($image); exit; }
foreach ($per_host as $index => $percent) { $week_day++; if ($week_day > 6) { $week_day -= 7; } if ($index / 2 == (int) ($index / 2)) { $color = imageColorAllocate($img, 249, 243, 70); $color2 = imageColorAllocate($img, 242, 226, 42); $color3 = imageColorAllocate($img, 226, 210, 34); } else { $color = imageColorAllocate($img, 11, 215, 252); $color2 = imageColorAllocate($img, 7, 203, 239); $color3 = imageColorAllocate($img, 7, 187, 219); } $y1 = round($imageW - $imageW * $percent + 12); imageFilledRectangle($img, $x1, $y1, $x2, $y2, $color); $points = array(0 => $x1, 1 => $y1, 2 => $x1 + 3, 3 => $y1 - 5, 4 => $x1 + $collW + 3, 5 => $y1 - 5, 6 => $x2, 7 => $y1); imageFilledPolygon($img, $points, 4, $color2); $points = array(0 => $x2, 1 => $y1, 2 => $x1 + $collW + 3, 3 => $y1 - 5, 4 => $x1 + $collW + 3, 5 => $y2 - 5, 6 => $x2, 7 => $y2); imageFilledPolygon($img, $points, 4, $color3); // imageTTFtext($img, 7, 90, $x1+8, 50, $colorBlack, BASEDIR.'/assets/fonts/font.ttf', $host_data[$index]); imagestringup($img, 1, $x1 + 3, 52, $host_data[$index], $colorBlack); imageTTFtext($img, 6, 0, $x1 + 3, 66, $colorBlack, BASEDIR . '/assets/fonts/font.ttf', $arr_week[$week_day]); $x1 += $collW; $x2 += $collW; } //Header("Content-type: image/gif"); ImageGIF($img, BASEDIR . $imagecache); ImageDestroy($img); } echo '<img src="' . $imagecache . '?' . date_fixed(SITETIME, "dmY") . '" alt="Неделя" /><br /><br />';
function cellplot($im, $sz, $C, $cellsize, $e) { list($sv, $el, $az, $snr, $u) = $e; if (0 == $sv || 0 == $az + $el + $snr || $az < 0 || $el < 0) { return; } $color = $C['brightgreen']; if ($snr < 40) { $color = $C['darkgreen']; } if ($snr < 35) { $color = $C['yellow']; } if ($snr < 30) { $color = $C['red']; } if ($snr < 15) { $color = $C['dkgray']; } #consider an N-degree cell plotted at (0,0). its top left corner #will be (0,0) and its bottom right corner will be at (N,N). The #sides are straight lines from (0,0)-(0,N) and (N,0)-(N,N). The #top and bottom edges will be approximated by segments from #(0,0):(0,1)..(0,N-1):(0,N) and (N,0):(N,1)...(N,N-1):(N,N). #Plotting that unholy mess is the job of # imagefilledpolygon ( $image, array $points, $num_points, $color ) $np = 0; $points = array(); for ($x = $az; $x <= $az + $cellsize; $x++) { list($px, $py) = azel2xy($x, $el, $sz); array_push($points, $px, $py); $np++; } for ($x = $az + $cellsize; $x >= $az; $x--) { list($px, $py) = azel2xy($x, $el + $cellsize, $sz); array_push($points, $px, $py); $np++; } list($px, $py) = azel2xy($az, $el, $sz); array_push($points, $px, $py); $np++; if ($snr > 0) { imageFilledPolygon($im, $points, $np, $color); } }
function draw_polygon($points, $num_points, $color, $filled) { if ($filled) { imageFilledPolygon($this->image, $points, $num_points, $color); } else { imagePolygon($this->image, $points, $num_points, $color); } }
/** * Function: drawPolygon * * Draws the given polygon. */ function drawPolygon($points, $fill = null, $stroke = null, $shadow = false) { if (isset($this->image)) { $n = sizeof($points) / 2; if (isset($fill)) { if ($shadow) { imageFilledPolygon($this->image, $this->offset($points), $n, $this->shadowColor); } $fill = $this->getColor($fill); imageFilledPolygon($this->image, $points, $n, $fill); } if (isset($stroke)) { $stroke = $this->getColor($stroke); imagePolygon($this->image, $points, $n, $stroke); } } }
/** * DrawShadowedPolygon is a wrapper to the imageFilledPolygon GD function that * first creates a drop shadow. * * @param $verts The vertices for the polygon * @param $color The color you want the polygon to be */ function DrawShadowedPolygon($verts, $color, $color) { for ($i = 0; $i < sizeof($verts); $i++) { $this->translate($verts[$i], $verts[$i + 1], $verts[$i], $verts[++$i]); } imageFilledPolygon($this->im, $verts, sizeof($verts) / 2, $color); }
<?php ## Увеличение картинки со сглаживанием. $tile = imageCreateFromJpeg("sample1.jpg"); $im = imageCreateTrueColor(800, 600); imageFill($im, 0, 0, imageColorAllocate($im, 0, 255, 0)); imageSetTile($im, $tile); // Создаем массив точек со случайными координатами. $p = []; for ($i = 0; $i < 4; $i++) { array_push($p, mt_rand(0, imageSX($im)), mt_rand(0, imageSY($im))); } // Рисуем закрашенный многоугольник. imageFilledPolygon($im, $p, count($p) / 2, IMG_COLOR_TILED); // Выводим результат. header("Content-type: image/jpeg"); // Выводим картинку с максимальным качеством (100). imageJpeg($im, '', 100); // Можно было сжать с помощью PNG. #header("Content-type: image/png"); #imagePng($im);