return $spec;
}
+ /**
+ * Given array( array('x' => 10, 'y' => 20), array( 'x' => 30, y=> 5 ) )
+ * returns "10,20 30,5"
+ * Useful for SVG and imagemagick command line arguments
+ * @param $shape: Array of arrays, each array containing x & y keys mapped to numeric values
+ * @return string
+ */
+ static function shapePointsToString( $shape ) {
+ $points = array();
+ foreach ( $shape as $point ) {
+ $points[] = $point['x'] . ',' . $point['y'];
+ }
+ return join( " ", $points );
+ }
/**
* Based on image specification, write a very simple SVG file to disk.
foreach ( $spec['draws'] as $drawSpec ) {
$shape = $g->addChild( 'polygon' );
$shape->addAttribute( 'fill', $drawSpec['fill'] );
- $shape->addAttribute( 'points', shapePointsToString( $drawSpec['shape'] ) );
+ $shape->addAttribute( 'points', self::shapePointsToString( $drawSpec['shape'] ) );
};
if ( ! $fh = fopen( $filename, 'w' ) ) {
throw new Exception( "couldn't open $filename for writing" );
}
}
- public function shapePointsToString( $shape ) {
- $points = array();
- foreach ( $shape as $point ) {
- $points[] = $point['x'] . ',' . $point['y'];
- }
- return join( " ", $points );
- }
-
/**
* Based on an image specification, write such an image to disk, using Imagick PHP extension
* @param $spec: spec describing background and circles to draw
$args[] = wfEscapeShellArg( "xc:" . $spec['fill'] );
foreach( $spec['draws'] as $draw ) {
$fill = $draw['fill'];
- $polygon = shapePointsToString( $draw['shape'] );
+ $polygon = self::shapePointsToString( $draw['shape'] );
$drawCommand = "fill $fill polygon $polygon";
$args[] = '-draw ' . wfEscapeShellArg( $drawCommand );
}