BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

image.class.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. if (!extension_loaded('gd')) {
  3. error('GD Extension not loaded.');
  4. }
  5. class IMAGE
  6. {
  7. public $Image = false;
  8. public $FontSize = 10;
  9. public $Font = '';
  10. public $TextAngle = 0;
  11. public function create($Width, $Height)
  12. {
  13. $this->Image = imagecreate($Width, $Height);
  14. $this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF';
  15. if (function_exists('imageantialias')) {
  16. imageantialias($this->Image, true);
  17. }
  18. }
  19. public function color($Red, $Green, $Blue, $Alpha = 0)
  20. {
  21. return imagecolorallocatealpha($this->Image, $Red, $Green, $Blue, $Alpha);
  22. }
  23. public function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1)
  24. {
  25. if ($Thickness === 1) {
  26. return imageline($this->Image, $x1, $y1, $x2, $y2, $Color);
  27. }
  28. $t = $Thickness / 2 - 0.5;
  29. if ($x1 === $x2 || $y1 === $y2) {
  30. 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);
  31. }
  32. $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
  33. $a = $t / sqrt(1 + pow($k, 2));
  34. $Points = array(
  35. round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a),
  36. round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a),
  37. round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a),
  38. round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a),
  39. );
  40. imagefilledpolygon($this->Image, $Points, 4, $Color);
  41. return imagepolygon($this->Image, $Points, 4, $Color);
  42. }
  43. public function ellipse($x, $y, $Width, $Height, $Color)
  44. {
  45. return imageEllipse($this->Image, $x, $y, $Width, $Height, $Color);
  46. }
  47. public function text($x, $y, $Color, $Text)
  48. {
  49. return imagettftext($this->Image, $this->FontSize, $this->TextAngle, $x, $y, $Color, $this->Font, $Text);
  50. }
  51. public function make_png($FileName = null)
  52. {
  53. return imagepng($this->Image, $FileName);
  54. }
  55. }