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

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