Gazelle/classes/class_image.php

59 lines
1.7 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
if (!extension_loaded('gd')) {
error('GD Extension not loaded.');
}
class IMAGE {
var $Image = false;
var $FontSize = 10;
var $Font = '';
var $TextAngle = 0;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
function create($Width, $Height) {
$this->Image = imagecreate($Width, $Height);
$this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF';
2013-04-20 08:01:01 +00:00
if (function_exists('imageantialias')) {
2011-03-28 14:21:28 +00:00
imageantialias($this->Image, true);
}
}
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
function color($Red, $Green, $Blue, $Alpha = 0) {
2011-03-28 14:21:28 +00:00
return imagecolorallocatealpha($this->Image, $Red, $Green, $Blue, $Alpha);
}
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1) {
if ($Thickness == 1) {
2011-03-28 14:21:28 +00:00
return imageline($this->Image, $x1, $y1, $x2, $y2, $Color);
}
$t = $Thickness / 2 - 0.5;
if ($x1 == $x2 || $y1 == $y2) {
return imagefilledrectangle($this->Image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
}
$k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
$a = $t / sqrt(1 + pow($k, 2));
$Points = array(
2013-04-20 08:01:01 +00:00
round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a),
round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a),
round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a),
round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a),
2011-03-28 14:21:28 +00:00
);
imagefilledpolygon($this->Image, $Points, 4, $Color);
return imagepolygon($this->Image, $Points, 4, $Color);
}
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
function ellipse($x, $y, $Width, $Height, $Color) {
2011-03-28 14:21:28 +00:00
return imageEllipse($this->Image, $x, $y, $Width, $Height, $Color);
}
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
function text($x, $y, $Color, $Text) {
2011-03-28 14:21:28 +00:00
return imagettftext ($this->Image, $this->FontSize,$this->TextAngle, $x, $y, $Color, $this->Font, $Text);
}
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
function make_png($FileName = NULL) {
2011-03-28 14:21:28 +00:00
return imagepng($this->Image, $FileName);
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
}
?>