function test_shape(&$canvas) { $draw = new ImagickDraw(); $draw->setFillColor('transparent'); $draw->setStrokeColor('#F02B88'); $draw->setStrokeWidth(9); $draw->translate(200, 100); $draw->rectangle(-50, -50, 50, 50); $draw->translate(200, 100); $draw->ellipse(0, 0, 100, 80, 0, 360); $draw->skewX(-30); $draw->translate(200, 100); $draw->circle(0, 0, 50, 50); $canvas->drawImage($draw); }
function renderImage3() { //dupe of two ? $draw = new \ImagickDraw(); $strokeColor = new \ImagickPixel($this->strokeColor); $fillColor = new \ImagickPixel($this->fillColor); $draw->setStrokeWidth(1); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); $fillRules = [\Imagick::FILLRULE_NONZERO, \Imagick::FILLRULE_EVENODD]; $points = 11; $size = 150; $draw->translate(175, 160); for ($x = 0; $x < 2; $x++) { //$pointsArray = array(); $draw->setFillRule($fillRules[$x]); $draw->pathStart(); for ($n = 0; $n < $points * 2; $n++) { if ($n >= $points) { $angle = fmod($n * 360 * 4 / $points, 360) * pi() / 180; } else { $angle = fmod($n * 360 * 3 / $points, 360) * pi() / 180; } $positionX = $size * sin($angle); $positionY = $size * cos($angle); if ($n == 0) { $draw->pathMoveToAbsolute($positionX, $positionY); } else { $draw->pathLineToAbsolute($positionX, $positionY); } } $draw->pathClose(); $draw->pathFinish(); $draw->translate(325, 0); } //Create an image object which the draw commands can be rendered into $image = new \Imagick(); //$image->newImage(700, 320, $this->backgroundColor); $image->newImage(700, 320, "#eee"); $image->setImageFormat("png"); //Render the draw commands in the ImagickDraw object //into the image. $image->drawImage($draw); //Send the image to the browser header("Content-Type: image/png"); echo $image->getImageBlob(); }
function makeSimpleGif($deconstruct) { $aniGif = new \Imagick(); $aniGif->setFormat("gif"); $circleRadius = 20; $imageFrames = 40; $imageSize = 200; $background = new \Imagick(); $background->newpseudoimage($imageSize, $imageSize, "plasma:tomato-steelblue"); $blackWhite = new \Imagick(); $blackWhite->newpseudoimage($imageSize, $imageSize, "gradient:black-white"); $backgroundPalette = clone $background; $backgroundPalette->quantizeImage(240, \Imagick::COLORSPACE_RGB, 8, false, false); $blackWhitePalette = clone $blackWhite; $blackWhitePalette->quantizeImage(16, \Imagick::COLORSPACE_RGB, 8, false, false); $backgroundPalette->addimage($blackWhitePalette); for ($count = 0; $count < $imageFrames; $count++) { $drawing = new \ImagickDraw(); $drawing->setFillColor('white'); $drawing->setStrokeColor('rgba(64, 64, 64, 0.8)'); $strokeWidth = 4; $drawing->setStrokeWidth($strokeWidth); $distanceToMove = $imageSize + ($circleRadius + $strokeWidth) * 2; $offset = $distanceToMove * $count / ($imageFrames - 1) - ($circleRadius + $strokeWidth); $drawing->translate($offset, $imageSize / 2 + $imageSize / 3 * cos(20 * $count / $imageFrames)); $drawing->circle(0, 0, $circleRadius, 0); $frame = clone $background; $frame->drawimage($drawing); $frame->clutimage($backgroundPalette); $frame->setImageDelay(10); $aniGif->addImage($frame); } if ($deconstruct == true) { $aniGif = $aniGif->deconstructImages(); } header("Content-Type: image/gif"); echo $aniGif->getImagesBlob(); }
function drawBezierChart($points, $roundness) { //Calculate the tangent vector for each point that you're drawing. $tangents = $this->getPointTangents($points); $positions = $this->getPointPositions($points); $numberOfPoints = count($points); $this->draw->setFillColor('#B42AAF9F'); $this->draw->translate($this->chartWidth / 2, $this->chartHeight / 2); $this->draw->pathStart(); $this->draw->pathMoveToAbsolute($positions[0][0], $positions[0][1]); //Scale that by the 'value' of each point aka the distance from the chart's centre. //Also scale it by how rounded you want the chart. for ($i = 0; $i < $numberOfPoints; $i++) { list($nextPositionX, $nextPositionY) = $positions[($i + 1) % $numberOfPoints]; list($controlPoint1X, $controlPoint1Y) = $this->getControlPoint($points[$i], $positions[$i], $tangents[$i], 1, $roundness, count($points)); list($controlPoint2X, $controlPoint2Y) = $this->getControlPoint($points[($i + 1) % $numberOfPoints], $positions[($i + 1) % $numberOfPoints], $tangents[($i + 1) % $numberOfPoints], -1, $roundness, count($points)); $this->draw->pathCurveToAbsolute($controlPoint1X, $controlPoint1Y, $controlPoint2X, $controlPoint2Y, $nextPositionX, $nextPositionY); } $this->draw->pathClose(); $this->draw->pathFinish(); foreach ($this->points as $point) { $this->draw->circle($point[0], $point[1], $point[2], $point[3]); } }
function renderKernel(ImagickKernel $imagickKernel) { $matrix = $imagickKernel->getMatrix(); $imageMargin = 20; $tileSize = 20; $tileSpace = 4; $shadowSigma = 4; $shadowDropX = 20; $shadowDropY = 0; $radius = $tileSize / 2 * 0.9; $rows = count($matrix); $columns = count($matrix[0]); $imagickDraw = new \ImagickDraw(); $imagickDraw->setFillColor('#afafaf'); $imagickDraw->setStrokeColor('none'); $imagickDraw->translate($imageMargin, $imageMargin); $imagickDraw->push(); ksort($matrix); foreach ($matrix as $row) { ksort($row); $imagickDraw->push(); foreach ($row as $cell) { if ($cell !== false) { $color = intval(255 * $cell); $colorString = sprintf("rgb(%f, %f, %f)", $color, $color, $color); $imagickDraw->setFillColor($colorString); $imagickDraw->rectangle(0, 0, $tileSize, $tileSize); } $imagickDraw->translate($tileSize + $tileSpace, 0); } $imagickDraw->pop(); $imagickDraw->translate(0, $tileSize + $tileSpace); } $imagickDraw->pop(); $width = $columns * $tileSize + ($columns - 1) * $tileSpace; $height = $rows * $tileSize + ($rows - 1) * $tileSpace; $imagickDraw->push(); $imagickDraw->translate($width / 2, $height / 2); $imagickDraw->setFillColor('rgba(0, 0, 0, 0)'); $imagickDraw->setStrokeColor('white'); $imagickDraw->circle(0, 0, $radius - 1, 0); $imagickDraw->setStrokeColor('black'); $imagickDraw->circle(0, 0, $radius, 0); $imagickDraw->pop(); $canvasWidth = $width + 2 * $imageMargin; $canvasHeight = $height + 2 * $imageMargin; $kernel = new \Imagick(); $kernel->newPseudoImage($canvasWidth, $canvasHeight, 'canvas:none'); $kernel->setImageFormat('png'); $kernel->drawImage($imagickDraw); /* create drop shadow on it's own layer */ $canvas = $kernel->clone(); $canvas->setImageBackgroundColor(new \ImagickPixel('rgb(0, 0, 0)')); $canvas->shadowImage(100, $shadowSigma, $shadowDropX, $shadowDropY); $canvas->setImagePage($canvasWidth, $canvasHeight, -5, -5); $canvas->cropImage($canvasWidth, $canvasHeight, 0, 0); /* composite original text_layer onto shadow_layer */ $canvas->compositeImage($kernel, \Imagick::COMPOSITE_OVER, 0, 0); $canvas->setImageFormat('png'); return $canvas; }
function whirlyGif($numberDots, $numberFrames, $loopTime, $backgroundColor, $phaseMultiplier, $phaseDivider) { $aniGif = new \Imagick(); $aniGif->setFormat("gif"); $width = 500; $height = $width; $numberDots = intval($numberDots); if ($numberDots < 1) { $numberDots = 1; } $maxFrames = $numberFrames; $frameDelay = ceil($loopTime / $maxFrames); $scale = 1; $startColor = new \ImagickPixel('red'); $dots = []; for ($i = 0; $i < $numberDots; $i++) { $colorInfo = $startColor->getHSL(); //Rotate the hue by 180 degrees $newHue = $colorInfo['hue'] + $i / $numberDots; if ($newHue > 1) { $newHue = $newHue - 1; } //Set the ImagickPixel to the new color $color = new \ImagickPixel('#ffffff'); $colorInfo['saturation'] *= 0.95; $color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']); $dots[] = new Dot($color, $i, $numberDots, $width, $height); } for ($frame = 0; $frame < $maxFrames; $frame++) { $draw = new \ImagickDraw(); $draw->setStrokeColor('none'); $draw->setFillColor('none'); $draw->rectangle(0, 0, $width, $height); $draw->translate($width / 2, $height / 2); foreach ($dots as $dot) { /** @var $dot Dot */ $dot->render($draw, $frame, $maxFrames, $phaseMultiplier, $phaseDivider); } //Create an image object which the draw commands can be rendered into $imagick = new \Imagick(); $imagick->newImage($width * $scale, $height * $scale, $backgroundColor); $imagick->setImageFormat("png"); $imagick->setImageDispose(\Imagick::DISPOSE_PREVIOUS); //Render the draw commands in the ImagickDraw object //into the image. $imagick->drawImage($draw); $imagick->setImageDelay($frameDelay); $aniGif->addImage($imagick); $imagick->destroy(); } $aniGif->setImageFormat('gif'); $aniGif->setImageIterations(0); //loop forever $aniGif->mergeImageLayers(\Imagick::LAYERMETHOD_OPTIMIZEPLUS); header("Content-Type: image/gif"); echo $aniGif->getImagesBlob(); }
function inici() { /* * Declaració de les variables apuntadores a l'array global. */ $array_notes = $GLOBALS['notes']; $nAlumnes = $GLOBALS['alumnes']; $pixels = $GLOBALS['pixels']; $marge = $GLOBALS['marge']; /* * Declaració del context ImagickDraw ($draw); translació del punt * d'origen a la cantonada inferior esquerra. * * Degut a que la Y augmenta en sentit descendent, els valors verticals * han d'augmentar negativament */ $draw = new \ImagickDraw(); $draw->translate($marge, 500 - $marge); /* * Crida de les funcions que dibuixen el gràfic. */ dibuixaEix($draw); dibuixaBarres($draw); /* * Declaració de la imatge (objecte $imagick) */ $imagick = new \Imagick(); $imagick->newImage($nAlumnes * $pixels + 2 * $marge, 500, $GLOBALS['backgroundColor']); $imagick->setImageFormat("png"); /* * Dibuix final de la imatge. Ara es quan apareix tot a la pantalla. */ $imagick->drawImage($draw); $imagick->setImageFormat("png"); file_put_contents("image/grafico.png", $imagick); /* * Misc. */ //header("Content-Type: image/png"); // echo $imagick->getImageBlob(); echo "<div id='container'><img src='/image/grafico.png'/></div>"; }
/** * Funció dibuixaEixos * Li pasem per els parametres el array assignatures i el array de notes * Creem el grafic, el guardem i el mostrem */ function dibuixaEixos($array_assignatura, $array_notes) { $colorAprobats = '#00cc00'; //fillColorA $colorSuspesos = '#ff0000'; //fillColorS $im = new Imagick(); $im->newImage(1400, 500, 'White'); $draw = new ImagickDraw(); $draw->translate(25, 500 - 25); //$draw->setFillColor('none'); $draw->setStrokeColor('Black'); $draw->setStrokeWidth(1); $draw->setFont("fonts/Aaargh.ttf"); $draw->setFontSize(12); /** * Dibuixa els eixos x i y * */ $draw->line(0, 0, 50 * count($array_assignatura) + 15, 0); //eix x _ $draw->line(0, 0, 0, -45 * 10); //eix y | /** * Dibuixa les linies del eix y * */ $n = 0; for ($i = 0; $i <= 45 * 10; $i++) { if ($i % 45 == 0) { $draw->line(0, -$i, -5, -$i); $draw->annotation(-15, -$i, $n); $n++; } } $draw->setFontSize(13); $i = 15; $n = 0; foreach ($array_notes as $nota) { if ($GLOBALS['aprosus']) { if ($nota < 5) { $draw->setFillColor($colorSuspesos); } else { $draw->setFillColor($colorAprobats); } } else { $draw->setFillColor('#0000ff'); } $draw->rectangle($i, 0, $i + 45, -$nota * 45); /* Escriu el text */ $draw->annotation($i, 15, $array_assignatura[$n]); $n++; $i = $i + 45 + 15; } $im->drawImage($draw); $im->setImageFormat("png"); //file_put_contents ("draw_polyline.png", $imagick); $im->writeImage('draw_grafic.jpg'); //echo $num_assig." i ".$max_notes; echo "<img src='draw_grafic.jpg'/>"; }
function translate($strokeColor, $fillColor, $backgroundColor, $fillModifiedColor, $startX, $startY, $endX, $endY, $translateX, $translateY) { $draw = new \ImagickDraw(); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); $draw->rectangle($startX, $startY, $endX, $endY); $draw->setFillColor($fillModifiedColor); $draw->translate($translateX, $translateY); $draw->rectangle($startX, $startY, $endX, $endY); $image = new \Imagick(); $image->newImage(500, 500, $backgroundColor); $image->setImageFormat("png"); $image->drawImage($draw); header("Content-Type: image/png"); echo $image->getImageBlob(); }
function inici() { /* * Declaració de les variables apuntadores a l'array global. */ $array_notes = $GLOBALS['notes']; $nAlumnes = $GLOBALS['alumnes']; $pixels = $GLOBALS['pixels']; $marge = $GLOBALS['marge']; $ampl = $GLOBALS['horitzontal']; $alt = $GLOBALS['vertical']; /* * Declaració de la imatge (objecte $imagick) */ $imagick = new \Imagick(); $imagick->newImage($ampl, $alt, $GLOBALS['backgroundColor']); $imagick->setImageFormat("png"); /* * Declaració del context ImagickDraw ($draw) i translació del punt * d'origen a la cantonada inferior esquerra. * * Degut a que la Y augmenta en sentit descendent, els VALORS VERTICALS * han de ser NEGATIUS per tal que el gràfic es dibuixi cap amunt. */ $draw = new \ImagickDraw(); $draw->translate($marge, $alt - 4 * $marge); /* * Crida de les funcions que dibuixen el gràfic. */ dibuixaEix($draw); dibuixaBarres($draw, $imagick); /* * Dibuix final de la imatge. Ara es quan apareix tot a la pantalla. */ $imagick->drawImage($draw); $imagick->setImageFormat("png"); file_put_contents("image/grafico.png", $imagick); echo "<div id='container'><img src='/image/grafico.png'/></div>"; }