cvs: pear /Image_GIS2 GIS.php package.xml /Image_GIS2/GIS LineSet.php Parser.php Renderer.php /Image_GIS2/GIS/Parser E00.php
/Image_GIS2/GIS/Renderer GD.php SVG.php /Image_GIS2/GIS2 LineSet.php Parser.php Renderer.php /Image_GIS2/GIS2/Parser E00.php
/Image_GIS2/GIS2/Renderer GD.php SVG.php

From: Date: Sat, 17 Apr 2004 10:33:46 +0000
Subject: cvs: pear /Image_GIS2 GIS.php package.xml /Image_GIS2/GIS LineSet.php Parser.php Renderer.php /Image_GIS2/GIS/Parser E00.php
/Image_GIS2/GIS/Renderer GD.php SVG.php /Image_GIS2/GIS2 LineSet.php Parser.php Renderer.php /Image_GIS2/GIS2/Parser E00.php
/Image_GIS2/GIS2/Renderer GD.php SVG.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-18342@lists.php.net to get a copy of this message
sebastian Sat Apr 17 06:33:46 2004 EDT Added files: /pear/Image_GIS2/GIS2 LineSet.php Parser.php Renderer.php /pear/Image_GIS2/GIS2/Parser E00.php /pear/Image_GIS2/GIS2/Renderer GD.php SVG.php Removed files: /pear/Image_GIS2/GIS LineSet.php Parser.php Renderer.php /pear/Image_GIS2/GIS/Parser E00.php /pear/Image_GIS2/GIS/Renderer GD.php SVG.php Modified files: /pear/Image_GIS2 GIS.php package.xml Log: Image_GIS->Image_GIS2

http://cvs.php.net/diff.php/pear/Image_GIS2/GIS.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_GIS2/GIS.php diff -u pear/Image_GIS2/GIS.php:1.1 pear/Image_GIS2/GIS.php:1.2 --- pear/Image_GIS2/GIS.php:1.1 Sat Apr 17 06:21:26 2004 +++ pear/Image_GIS2/GIS.php Sat Apr 17 06:33:44 2004 @@ -13,12 +13,12 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: GIS.php,v 1.1 2004/04/17 10:21:26 sebastian Exp $ +// $Id: GIS.php,v 1.2 2004/04/17 10:33:44 sebastian Exp $ // require_once 'Image/Color.php'; -require_once 'Image/GIS/Parser.php'; -require_once 'Image/GIS/Renderer.php'; +require_once 'Image/GIS2/Parser.php'; +require_once 'Image/GIS2/Renderer.php'; /** * The following example draws the region around the @@ -26,10 +26,10 @@ * * <code> * <?php - * require_once 'Image/GIS.php'; + * require_once 'Image/GIS2.php'; * * // Create new map. - * $map = new Image_GIS( + * $map = new Image_GIS2( * array( * 'width' => 960, * 'height' => 1280, @@ -62,9 +62,9 @@ * @copyright Copyright &copy; 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image - * @package Image_GIS + * @package Image_GIS2 */ -class Image_GIS { +class Image_GIS2 { /** * Set to TRUE to enable debugging. * @@ -73,16 +73,16 @@ private $debug; /** - * Image_GIS_Parser sub-class object. + * Image_GIS2_Parser sub-class object. * - * @var Image_GIS_Parser $parser + * @var Image_GIS2_Parser $parser */ private $parser; /** - * Image_GIS_Renderer sub-class object. + * Image_GIS2_Renderer sub-class object. * - * @var Image_GIS_Renderer $renderer + * @var Image_GIS2_Renderer $renderer */ private $renderer; @@ -137,7 +137,6 @@ * * @return array * @access public - * @since Image_GIS 1.0.1 */ public function getRange() { return $this->renderer->getRange(); @@ -166,7 +165,7 @@ } /** - * Sets the Image_GIS_Parser sub-class to be used + * Sets the Image_GIS2_Parser sub-class to be used * to parse a data file. * * @param string $parser @@ -174,7 +173,7 @@ * @access public */ public function setParser($parser, $cache) { - $this->parser = Image_GIS_Parser::factory($parser, $cache, $this->debug); + $this->parser = Image_GIS2_Parser::factory($parser, $cache, $this->debug); } /** @@ -191,14 +190,14 @@ } /** - * Sets the Image_GIS_Renderer sub-class to be used + * Sets the Image_GIS2_Renderer sub-class to be used * to render an image. * * @param string $renderer * @access public */ public function setRenderer($renderer, $width, $height) { - $this->renderer = Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); + $this->renderer = Image_GIS2_Renderer::factory($renderer, $width, $height, $this->debug); } /** http://cvs.php.net/diff.php/pear/Image_GIS2/package.xml?r1=1.1&r2=1.2&ty=u Index: pear/Image_GIS2/package.xml diff -u pear/Image_GIS2/package.xml:1.1 pear/Image_GIS2/package.xml:1.2 --- pear/Image_GIS2/package.xml:1.1 Sat Apr 17 06:21:26 2004 +++ pear/Image_GIS2/package.xml Sat Apr 17 06:33:44 2004 @@ -40,7 +40,7 @@ </notes> <filelist> <dir name="/" baseinstalldir="Image"> - <dir name="GIS"> + <dir name="GIS2"> <dir name="Parser"> <file role="php" name="E00.php"/> </dir> @@ -65,45 +65,4 @@ <dep type="pkg" rel="has">XML_SVG</dep> </deps> </release> - <changelog> - <release> - <version>1.1.0</version> - <state>stable</state> - <date>2004-01-06</date> - <notes> -<![CDATA[ -+ Added caching of parsed data files. - -+ Added getRange() method to the Image_GIS and Image_GIS_Renderer - classes. - -* Changed the Image_GIS constructor to accept an associative - parameter array as its only argument. - - Note: This breaks backwards compatibility. - -* The SVG renderer now uses the XML_SVG package instead of the - XML_Tree package. - -* Factored the handling of Line Sets out into a separate class. - -* Fixed handling of negative coordinates. - -* Fixed a bug that kept a debugging message from beeing printed. - -* Fixed incompatibilities with PHP 5. -]]> - </notes> - </release> - <release> - <version>1.0.0</version> - <state>stable</state> - <date>2002-12-30</date> - <notes> -<![CDATA[ -* Initial release. -]]> - </notes> - </release> - </changelog> </package> http://cvs.php.net/co.php/pear/Image_GIS2/GIS2/LineSet.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS2/LineSet.php +++ pear/Image_GIS2/GIS2/LineSet.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Line Set | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: LineSet.php,v 1.1 2004/04/17 10:33:45 sebastian Exp $ // /** * A Set of Lines. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright &copy; 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS2 */ class Image_GIS2_LineSet { /** * @var array $color */ public $color = 'black'; /** * @var array $lines */ public $lines = array(); /** * @var array $min */ public $min = array( 'x' => 0, 'y' => 0 ); /** * @var array $max */ public $max = array( 'x' => 0, 'y' => 0 ); /** * Constructor. * * @param string $color * @access public */ public function Image_GIS2_LineSet($color = 'black') { $this->color = $color; } /** * Adds a line to the line set. * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @access public */ public function addLine($x1, $y1, $x2, $y2) { $this->lines[] = array($x1, $y1, $x2, $y2); $this->min['x'] = min($this->min['x'], $x1, $x2); $this->min['y'] = min($this->min['y'], $y1, $y2); $this->max['x'] = max($this->max['x'], $x1, $x2); $this->max['y'] = max($this->max['y'], $y1, $y2); } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS2/Parser.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS2/Parser.php +++ pear/Image_GIS2/GIS2/Parser.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Parser Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: Parser.php,v 1.1 2004/04/17 10:33:45 sebastian Exp $ // require_once 'Cache/Lite.php'; require_once 'Image/GIS2/LineSet.php'; /** * Parser Base Class. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright &copy; 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS2 */ abstract class Image_GIS2_Parser { /** * Cache. * * @var Cache_Lite $cache */ protected $cache = NULL; /** * Data Files. * * @var array $dataFiles */ protected $dataFiles = array(); /** * Set to TRUE to enable debugging. * * @var boolean $debug */ protected $debug; /** * Line Set. * * @var array $lineSets */ protected $lineSets = array(); /** * Constructor. * * @param boolean $cache * @param boolean $debug * @access public */ public function Image_GIS2_Parser($cache, $debug) { if ($cache) { $this->cache = new Cache_Lite; } $this->debug = $debug; } /** * Factory. * * @param string $parser * @param boolean $cache * @param boolean $debug * @return object * @access public */ public static function factory($parser, $cache, $debug) { include_once 'Image/GIS2/Parser/' . $parser . '.php'; $class = 'Image_GIS2_Parser_' . $parser; $object = new $class($cache, $debug); return $object; } /** * Adds a datafile to the map. * * @param string $dataFile * @param mixed $color * @access public */ public function addDataFile($dataFile, $color) { $this->dataFiles[$dataFile] = $color; } /** * Parses the data files of the map. * * @access public * @return array */ public function parse() { foreach ($this->dataFiles as $dataFile => $color) { $cacheID = md5($dataFile . '_' . $color); $lineSet = false; if (is_object($this->cache) && $lineSet = $this->cache->get($cacheID, 'Image_GIS')) { $lineSet = unserialize($lineSet); } if ($lineSet === false) { $lineSet = $this->parseFile($dataFile, $color); if (is_object($this->cache)) { $this->cache->save(serialize($lineSet), $cacheID, 'Image_GIS'); } } $this->lineSets[] = $lineSet; } return $this->lineSets; } /** * Parses a data file. * * @param string $dataFile * @param mixed $color * @return mixed * @access public * @abstract */ public abstract function parseFile($dataFile, $color); } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS2/Renderer.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS2/Renderer.php +++ pear/Image_GIS2/GIS2/Renderer.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Renderer Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: Renderer.php,v 1.1 2004/04/17 10:33:45 sebastian Exp $ // require_once 'Image/Color.php'; /** * Renderer Base Class. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright &copy; 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS2 * @abstract */ abstract class Image_GIS2_Renderer { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ protected $debug; /** * @var array $min */ protected $min = false; /** * @var array $max */ protected $max = false; /** * Width of the image. * * @var integer $width */ protected $width; /** * Height of the image. * * @var integer $height */ protected $height; /** * Constructor. * * @param mixed $width * @param integer $height * @param boolean $debug * @access public */ public function Image_GIS2_Renderer($width, $height, $debug) { $this->debug = $debug; if ($width < 0 || $width > 2048) { $width = 640; } if ($height < 0 || $height > 2048) { $height = 480; } $this->width = $width; $this->height = $height; } /** * Factory. * * @param string $renderer * @param mixed $width * @param integer $height * @param boolean $debug * @return object * @access public */ public static function factory($renderer, $width, $height, $debug) { if (@include_once('Image/GIS2/Renderer/' . $renderer . '.php')) { $class = 'Image_GIS2_Renderer_' . $renderer; $object = new $class($width, $height, $debug); return $object; } } /** * Draws a clipped line from ($x1, $y1) to ($x2, $y2) * using $color. * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param mixed $color * @access public */ public function drawClippedLine($x1, $y1, $x2, $y2, $color) { if (($x1 > $this->max['x'] || $x1 < $this->min['x'] || $y1 > $this->max['y'] || $y1 < $this->min['y']) && ($x2 > $this->max['x'] || $x2 < $this->min['x'] || $y2 > $this->max['y'] || $y2 < $this->min['y'])) { if ($this->debug) { printf('clipped x1: %d %d %d<br />', $x1, $this->min['x'], $this->max['x']); printf('clipped y1: %d %d %d<br />', $y1, $this->min['y'], $this->max['y']); printf('clipped x2: %d %d %d<br />', $x2, $this->min['x'], $this->max['x']); printf('clipped y2: %d %d %d<br />', $y2, $this->min['y'], $this->max['y']); } } else { if (!is_array($color)) { $color = Image_Color::namedColor2RGB($color); } $x1 = $this->polar2image($x1, 'x'); $y1 = $this->polar2image($y1, 'y'); $x2 = $this->polar2image($x2, 'x'); $y2 = $this->polar2image($y2, 'y'); if ($this->debug) { printf('Drawing line (%s, %s) -> (%s, %s)<br />', $x1, $y1, $x2, $y2); } $this->drawLine($x1, $y1, $x2, $y2, $color[0], $color[1], $color[2]); } } /** * Returns the range of the data to be rendered. * * @return array * @access public */ public function getRange() { return array( $this->min['x'], $this->max['x'], $this->min['y'], $this->max['y'] ); } /** * Converts a polar coordinate to an image coordinate. * * @param float $polarCoordinate * @param string $direction * @access public */ public function polar2image($polarCoordinate, $direction) { switch ($direction) { case 'x': { return ($polarCoordinate - $this->min[$direction]) * ($this->width / ($this->max[$direction] - $this->min[$direction])); } break; case 'y': { return ($polarCoordinate - $this->max[$direction]) * ($this->height / ($this->min[$direction] - $this->max[$direction])); } break; } } /** * Renders the image. * * @param array $lineSets * @access public */ public function render($lineSets) { if ($this->min == false || $this->max == false) { $this->min = array( 'x' => 0, 'y' => 0 ); $this->max = array( 'x' => 0, 'y' => 0 ); foreach ($lineSets as $lineSet) { $this->min['x'] = min($this->min['x'], $lineSet->min['x']); $this->min['y'] = min($this->min['y'], $lineSet->min['y']); $this->max['x'] = max($this->max['x'], $lineSet->max['x']); $this->max['y'] = max($this->max['y'], $lineSet->max['y']); } } foreach ($lineSets as $lineSet) { foreach ($lineSet->lines as $line) { $this->drawClippedLine($line[0], $line[1], $line[2], $line[3], $lineSet->color); } } } /** * Sets the range of the data to be rendered. * * @param float $x1 * @param float $x2 * @param float $y1 * @param float $y2 * @access public */ public function setRange($x1, $x2, $y1, $y2) { $this->min = array('x' => $x1, 'y' => $y1); $this->max = array('x' => $x2, 'y' => $y2); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public * @abstract */ public abstract function drawLine($x1, $y1, $x2, $y2, $r, $g, $b); /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public * @abstract */ public abstract function saveImage($filename); /** * Shows the rendered image. * * @access public * @abstract */ public abstract function showImage(); } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS2/Parser/E00.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS2/Parser/E00.php +++ pear/Image_GIS2/GIS2/Parser/E00.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: E00 Parser | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: E00.php,v 1.1 2004/04/17 10:33:45 sebastian Exp $ // require_once 'Image/GIS2/LineSet.php'; require_once 'Image/GIS2/Parser.php'; /** * E00 Parser. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright &copy; 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS2 */ class Image_GIS2_Parser_E00 extends Image_GIS2_Parser { /** * Constructor. * * @param boolean $cache * @param boolean $debug * @access public */ public function Image_GIS2_Parser_E00($cache, $debug) { $this->Image_GIS2_Parser($cache, $debug); } /** * Parses a data file. * * @param string $dataFile * @param mixed $color * @return mixed * @access public */ public function parseFile($dataFile, $color) { $lineSet = new Image_GIS2_LineSet($color); if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; $lineNum = 0; while(0 || $line = fgets($fp, 1024)) { $lineNum++; if ($numRecords == 0 && preg_match("#^\s+([0-9]+)\s+([-0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)#", $line, $a)) { $numRecords = $a[7]; $pl['x'] = -1; $pl['y'] = -1; } else if ($numRecords && preg_match("#^[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) { if ($this->debug) { echo $a[0] . '<br />'; } if ($pl['x'] != -1 && $pl['y'] != -1) { $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); } $numRecords--; $lineSet->addLine($a[1], $a[2], $a[3], $a[4]); $pl['x'] = $a[3]; $pl['y'] = $a[4]; $numRecords--; } else if ($numRecords && preg_match("#^[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) { if ($pl['x'] != -1 && $pl['y'] != -1) { $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); $pl['x'] = $a[1]; $pl['y'] = $a[2]; } $numRecords--; } else if ($lineNum > 2) { if ($this->debug) { printf( 'Died at: %s<br />', $lineNum ); } break; } else if ($this->debug) { echo $line . '<br />'; } } @fclose($fp); return $lineSet; } return false; } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS2/Renderer/GD.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS2/Renderer/GD.php +++ pear/Image_GIS2/GIS2/Renderer/GD.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: GD Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: GD.php,v 1.1 2004/04/17 10:33:46 sebastian Exp $ // require_once 'Image/GIS2/Renderer.php'; /** * GD Renderer. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright &copy; 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS2 */ class Image_GIS2_Renderer_GD extends Image_GIS2_Renderer { /** * GD Image Ressource. * * @var ressource $image */ private $image; /** * GD Image Palette. * * @var array $palette */ private $palette = array(); /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ public function __construct($width, $height, $debug) { if (is_file($width)) { $this->image = imagecreatefrompng($width); $width = imagesx($this->image); $height = imagesy($this->image); } else { $this->image = imagecreate($this->width, $this->height); imagecolorallocate($this->image, 255, 255, 255); } $this->Image_GIS2_Renderer($width, $height, $debug); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public */ public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { if (!isset($this->palette[$r][$g][$b])) { $this->palette[$r][$g][$b] = imagecolorallocate($this->image, $r, $g, $b); } imageline( $this->image, $x1, $y1, $x2, $y2, $this->palette[$r][$g][$b] ); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ public function saveImage($filename) { return imagepng($this->image, $filename); } /** * Shows the rendered image. * * @access public */ public function showImage() { header('Content-Type: image/png'); imagepng($this->image); } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS2/Renderer/SVG.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS2/Renderer/SVG.php +++ pear/Image_GIS2/GIS2/Renderer/SVG.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: SVG Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: SVG.php,v 1.1 2004/04/17 10:33:46 sebastian Exp $ // require_once 'Image/GIS2/Renderer.php'; require_once 'XML/SVG.php'; /** * SVG Renderer. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright &copy; 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS2 */ class Image_GIS2_Renderer_SVG extends Image_GIS2_Renderer { /** * SVG Document. * * @var XML_SVG $svg */ private $svg; /** * SVG Groups. * * @var XML_SVG_Group[] */ private $svgGroups = array(); /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ public function __construct($width, $height, $debug) { $this->Image_GIS2_Renderer($width, $height, $debug); $this->svg = new XML_SVG_Document( array( 'width' => $width, 'height' => $height ) ); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public */ public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { $group = md5($r . $g . $b); if (!isset($this->svgGroups[$group])) { $this->svgGroups[$group] = new XML_SVG_Group( array( 'style' => sprintf( 'stroke:rgb(%s, %s, %s)', $r, $g, $b ) ) ); $this->svgGroups[$group]->addParent($this->svg); } $line = new XML_SVG_Line( array( 'x1' => $x1, 'y1' => $y1, 'x2' => $x2, 'y2' => $y2, ) ); $this->svgGroups[$group]->addChild($line); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ public function saveImage($filename) { if ($fp = @fopen($filename, 'w')) { @fputs($fp, $this->svg->bufferObject()); @fclose($fp); return true; } return false; } /** * Shows the rendered image. * * @access public */ public function showImage() { $this->svg->printElement(); } } ?>
« previous php.pear.cvs (#18342) next »