public function brushpng($color, $size, $brushpath) { $info = $this->_handle->getImageGeometry(); $image = new \Imagick(); $image->newImage($info["width"], $info["height"], "transparent", "png"); //$image->setImageFormat("png"); $draw = new \ImagickDraw(); $pixel = new \ImagickPixel(); $pixel->setColor("transparent"); $draw->setFillColor($pixel); $pixel->setColor($color); $draw->setStrokeColor($pixel); $draw->setStrokeWidth($size); $draw->setStrokeLineCap(\imagick::LINECAP_ROUND); $draw->setStrokeLineJoin(\imagick::LINEJOIN_ROUND); $draw->polyline($brushpath); $image->drawImage($draw); $pixel->destroy(); $draw->destroy(); $this->_handle = $image; }
var_dump($draw->getClipRule() === Imagick::FILLRULE_NONZERO); // gravity $draw->setGravity(Imagick::GRAVITY_SOUTHEAST); var_dump($draw->getGravity() === Imagick::GRAVITY_SOUTHEAST); // stroke $draw->setStrokeAntialias(false); var_dump($draw->getStrokeAntialias()); $draw->setStrokeColor(new ImagickPixel('#F02B88')); var_dump($draw->getStrokeColor()->getColor()); $draw->setStrokeDashArray(array(1, 2, 3)); var_dump($draw->getStrokeDashArray()); $draw->setStrokeDashOffset(-1); var_dump($draw->getStrokeDashOffset()); $draw->setStrokeLineCap(Imagick::LINECAP_SQUARE); var_dump($draw->getStrokeLineCap() === Imagick::LINECAP_SQUARE); $draw->setStrokeLineJoin(Imagick::LINEJOIN_BEVEL); var_dump($draw->getStrokeLineJoin() === Imagick::LINEJOIN_BEVEL); $draw->setStrokeMiterLimit(3); var_dump($draw->getStrokeMiterLimit()); $draw->setStrokeOpacity(0.9); printf("%.2f\n", $draw->getStrokeOpacity()); $draw->setStrokeWidth(1.2); printf("%.2f\n", $draw->getStrokeWidth()); // text $draw->setTextAlignment(Imagick::ALIGN_CENTER); var_dump($draw->getTextAlignment() === Imagick::ALIGN_CENTER); $draw->setTextAntialias(false); var_dump($draw->getTextAntialias()); $draw->setTextDecoration(Imagick::DECORATION_LINETROUGH); var_dump($draw->getTextDecoration() === Imagick::DECORATION_LINETROUGH); $draw->setTextEncoding('UTF-8');
function setStrokeMiterLimit($strokeColor, $fillColor, $backgroundColor) { $draw = new \ImagickDraw(); $draw->setStrokeColor($strokeColor); $draw->setStrokeOpacity(0.6); $draw->setFillColor($fillColor); $draw->setStrokeWidth(10); $yOffset = 100; $draw->setStrokeLineJoin(\Imagick::LINEJOIN_MITER); for ($y = 0; $y < 3; $y++) { $draw->setStrokeMiterLimit(40 * $y); $points = [['x' => 22 * 3, 'y' => 15 * 4 + $y * $yOffset], ['x' => 20 * 3, 'y' => 20 * 4 + $y * $yOffset], ['x' => 70 * 5, 'y' => 45 * 4 + $y * $yOffset]]; $draw->polygon($points); } $image = new \Imagick(); $image->newImage(500, 500, $backgroundColor); $image->setImageFormat("png"); $image->drawImage($draw); $image->setImageType(\Imagick::IMGTYPE_PALETTE); //TODO - this should either be everywhere or nowhere $image->setImageCompressionQuality(100); $image->stripImage(); header("Content-Type: image/png"); echo $image->getImageBlob(); }
/** * * * @param * * @return void */ private function drawPolygon($event, $au_scalar, &$polyOffsetX, &$polyOffsetY, &$polygonURL, &$polyWidth, &$polyHeight) { $originX = null; $originY = null; $polygonURL = null; $maxPixelScale = 0.60511022; // arcseconds per pixel $polyString = $event['hpc_boundcc']; $polyString = str_replace(array('POLYGON', '(', ')'), '', $polyString); foreach (explode(',', $polyString) as $xy) { list($x_coord, $y_coord) = explode(' ', $xy); $x[] = $x_coord * $au_scalar; $y[] = -$y_coord * $au_scalar; } $originX = min($x); $originY = min($y); $polyOffsetX = $originX; $polyOffsetY = $originY; $width = 0; $height = 0; for ($i = 0; $i < count($x); $i++) { $xCoord = ($x[$i] - $originX) / $maxPixelScale; $yCoord = ($y[$i] - $originY) / $maxPixelScale; $polyArray[] = array('x' => $xCoord, 'y' => $yCoord); if ($xCoord > $width) { $width = $xCoord; } if ($yCoord > $height) { $height = $yCoord; } } /* Create a new imagick object */ $im = new Imagick(); /* Create ImagickDraw object */ $draw = new ImagickDraw(); $strokeWidth = 4; $draw->setStrokeLineJoin(Imagick::LINEJOIN_ROUND); $draw->setStrokeColor('#00000088'); $draw->setStrokeWidth($strokeWidth); $draw->setStrokeAntialias(true); $draw->setFillColor('#' . $GLOBALS['HEK_COLORS'][$event['event_type']] . '66'); $draw->polygon($polyArray); $polyWidth = $width + $strokeWidth; $polyHeight = $height + $strokeWidth; /* Create a new canvas object and a transparent image */ $canvas = new Imagick(); $canvas->newImage($polyWidth, $polyHeight, 'none'); /* Draw the ImagickDraw on to the canvas */ $canvas->drawImage($draw); /* Set the format to PNG */ $canvas->setImageFormat('png'); $canvas->setInterlaceScheme(Imagick::INTERLACE_PNG); /* Output the image */ $dateArray = date_parse($event['event_starttime']); $cache_base_dir = HV_CACHE_DIR . '/events/' . $dateArray['year'] . '/' . str_pad($dateArray['month'], 2, '0', STR_PAD_LEFT) . '/' . str_pad($dateArray['day'], 2, '0', STR_PAD_LEFT); // Check for existence of cache sub-directory if (!@file_exists($cache_base_dir)) { @mkdir($cache_base_dir, 0777, true); } $cache_file = rawurlencode($event['kb_archivid']) . '.png'; $cache_file_path = $cache_base_dir . '/' . $cache_file; $polygonURL = str_replace(HV_CACHE_DIR, 'cache', $cache_base_dir) . '/' . rawurlencode($cache_file); $fp = @fopen($cache_file_path, 'wb'); if ($fp !== false) { @fwrite($fp, $canvas); @fclose($fp); } }