/** * Draws a polygon on the handle * * @param ImageMagick-object $handle The handle on which the polygon is drawn * @param Zend_Image_Action_DrawPolygon $polygon The object that with all info */ public function perform($handle, Zend_Image_Action_DrawPolygon $polygon) { // As of ZF2.0 / PHP5.3, this can be made static. $points = $this->_parsePoints($polygon->getPoints()); if ($polygon->isClosed()){ //add first point at the end to close $points[count($points)] = $points[0]; } $draw = new ImagickDraw(); $draw->setStrokeColor('#' . $polygon->getStrokeColor()->getHex()); $draw->setStrokeOpacity($polygon->getStrokeAlpha()/100); $draw->setStrokeWidth($polygon->getStrokeWidth()); $strokeDashArray = $polygon->getStrokeDashPattern(); if (count($strokeDashArray) > 0){ $draw->setStrokeDashArray($strokeDashArray); } $draw->setStrokeDashOffset($polygon->getStrokeDashOffset()); if($polygon->isFilled()) { $fillColor = $polygon->getFillColor(); $draw->setFillColor('#' . $fillColor->getHex()); $draw->polygon($points); } else { //Use transparent fill to render unfilled $draw->setFillOpacity(0); $draw->polyline($points); } $handle->getHandle()->drawImage($draw); }
/** * Draws a polygon on the handle * * @param GD-object $handle The handle on which the polygon is drawn * @param Zend_Image_Action_DrawPolygon $polygonObject The object that with all info */ public function perform(Zend_Image_Adapter_Gd $adapter, Zend_Image_Action_DrawPolygon $polygonObject) { // As of ZF2.0 / PHP5.3, this can be made static. $handle = $adapter->getHandle(); $points = $this->_parsePoints($polygonObject->getPoints()); if(($pattern = $polygonObject->getStrokeDashPattern())!== null) { $color = imagecolorallocate($handle, 0, 255, 0); $array = array(); foreach($pattern as $amountOfPixels) { $array = array_merge($array, array_fill(0, $amountOfPixels, $color)); $array = array_merge($array, array_fill(0, $polygonObject->getStrokeDashOffset(), IMG_COLOR_TRANSPARENT)); } if(count($array) > 0) { imagesetstyle($handle, $array); } } if($polygonObject->isFilled()) { //@TODO: extract this to Zend_Image_Adapter_Gd_Action_ActionAbstract ? $color = $polygonObject->getFillColor()->getRgb(); $colorRes = imagecolorallocatealpha($handle, $color['red'], $color['green'], $color['blue'], $polygonObject->getFillAlpha()); imagefilledpolygon($handle, $points, count($points)/2, $colorRes); } $points = $polygonObject->getPoints(); $start = current($points);; $line = new Zend_Image_Action_DrawLine(); while(current($points)!==false) { $from = current($points); $to = next($points); if($to===false) { if(!$polygonObject->isClosed()) { break; } else { $to = $start; } } $line->from($from); $line->to($to); $line->perform($adapter); } }