-
Notifications
You must be signed in to change notification settings - Fork 1
/
GD.php
118 lines (107 loc) · 3.3 KB
/
GD.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
//
// +------------------------------------------------------------------------+
// | PEAR :: Image :: GIS :: GD Renderer |
// +------------------------------------------------------------------------+
// | Copyright (c) 2002-2005 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$
//
require_once 'Image/GIS2/Renderer.php';
/**
* GD Renderer.
*
* @author Jan Kneschke <jan@kneschke.de>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright Copyright © 2002-2005 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);
}
}
?>