home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Image / GIS / Renderer / GD.php next >
Encoding:
PHP Script  |  2008-07-02  |  3.4 KB  |  119 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: GD Renderer                                    |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and             |
  7. // |                         Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  8. // +------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,        |
  10. // | that is available at http://www.php.net/license/3_0.txt.               |
  11. // | If you did not receive a copy of the PHP license and are unable to     |
  12. // | obtain it through the world-wide-web, please send a note to            |
  13. // | license@php.net so we can mail you a copy immediately.                 |
  14. // +------------------------------------------------------------------------+
  15. //
  16. // $Id: GD.php,v 1.7 2004/04/17 10:21:26 sebastian Exp $
  17. //
  18.  
  19. require_once 'Image/GIS/Renderer.php';
  20.  
  21. /**
  22.  * GD Renderer.
  23.  *
  24.  * @author      Jan Kneschke <jan@kneschke.de>
  25.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  26.  * @copyright   Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de>
  27.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  28.  * @category    Image
  29.  * @package     Image_GIS
  30.  */
  31. class Image_GIS_Renderer_GD extends Image_GIS_Renderer {
  32.     /**
  33.     * GD Image Palette.
  34.     *
  35.     * @var array $palette
  36.     */
  37.     var $palette = array();
  38.  
  39.     /**
  40.     * GD Image Ressource.
  41.     *
  42.     * @var ressource $img
  43.     */
  44.     var $img;
  45.  
  46.     /**
  47.     * Constructor.
  48.     *
  49.     * @param  mixed   $width
  50.     * @param  integer $sizyY
  51.     * @param  boolean $debug
  52.     * @access public
  53.     */
  54.     function Image_GIS_Renderer_GD($width, $height, $debug) {
  55.         if (is_file($width)) {
  56.             $this->img = imagecreatefrompng($width);
  57.             $width     = imagesx($this->img);
  58.             $height    = imagesy($this->img);
  59.  
  60.             $this->Image_GIS_Renderer($width, $height, $debug);
  61.         } else {
  62.             $this->Image_GIS_Renderer($width, $height, $debug);
  63.  
  64.             $this->img = imagecreate($this->width, $this->height);
  65.             imagecolorallocate($this->img, 255, 255, 255);
  66.         }
  67.     }
  68.  
  69.     /**
  70.     * Draws a line from ($x1, $y1) to ($x2, $y2)
  71.     * using the color rgb($r, $g, $b).
  72.     *
  73.     * @param  float   $x1
  74.     * @param  float   $y1
  75.     * @param  float   $x2
  76.     * @param  float   $y2
  77.     * @param  float   $r
  78.     * @param  float   $g
  79.     * @param  float   $b
  80.     * @access public
  81.     */
  82.     function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) {
  83.         if (!isset($this->palette[$r][$g][$b])) {
  84.             $this->palette[$r][$g][$b] = imagecolorallocate($this->img, $r, $g, $b);
  85.         }
  86.  
  87.         imageline(
  88.           $this->img,
  89.           $x1,
  90.           $y1,
  91.           $x2,
  92.           $y2,
  93.           $this->palette[$r][$g][$b]
  94.         );
  95.     }
  96.  
  97.     /**
  98.     * Saves the rendered image to a given file.
  99.     *
  100.     * @param  string  $filename
  101.     * @return boolean
  102.     * @access public
  103.     */
  104.     function saveImage($filename) {
  105.         return imagepng($this->img, $filename);
  106.     }
  107.  
  108.     /**
  109.     * Shows the rendered image.
  110.     *
  111.     * @access public
  112.     */
  113.     function showImage() {
  114.         header('Content-Type: image/png');
  115.         imagepng($this->img);
  116.     }
  117. }
  118. ?>
  119.