PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/prototype/smooth-line.php

https://github.com/dskvr/Graffitar
PHP | 82 lines | 54 code | 10 blank | 18 comment | 11 complexity | a4318efe0f90e45c92de270e1c453b4a MD5 | raw file
Possible License(s): GPL-3.0, Apache-2.0
  1. <?php
  2. /**
  3. * function imageSmoothAlphaLine() - version 1.0
  4. * Draws a smooth line with alpha-functionality
  5. *
  6. * @param ident the image to draw on
  7. * @param integer x1
  8. * @param integer y1
  9. * @param integer x2
  10. * @param integer y2
  11. * @param integer red (0 to 255)
  12. * @param integer green (0 to 255)
  13. * @param integer blue (0 to 255)
  14. * @param integer alpha (0 to 127)
  15. *
  16. * @access public
  17. *
  18. * @author DASPRiD <d@sprid.de>
  19. */
  20. function imageSmoothAlphaLine ($im, $x1, $y1, $x2, $y2, $r, $g, $b, $alpha=0) {
  21. $icr = $r;
  22. $icg = $g;
  23. $icb = $b;
  24. $dcol = imagecolorallocatealpha($im, $icr, $icg, $icb, $alpha);
  25. if ($y1 == $y2 || $x1 == $x2)
  26. imageline($im, $x1, $y2, $x1, $y2, $dcol);
  27. else {
  28. $m = ($y2 - $y1) / ($x2 - $x1);
  29. $b = $y1 - $m * $x1;
  30. if (abs ($m) <2) {
  31. $x = min($x1, $x2);
  32. $endx = max($x1, $x2) + 1;
  33. while ($x < $endx) {
  34. $y = $m * $x + $b;
  35. $ya = ($y == floor($y) ? 1: $y - floor($y));
  36. $yb = ceil($y) - $y;
  37. $trgb = ImageColorAt($im, $x, floor($y));
  38. $tcr = ($trgb >> 16) & 0xFF;
  39. $tcg = ($trgb >> 8) & 0xFF;
  40. $tcb = $trgb & 0xFF;
  41. imagesetpixel($im, $x, floor($y), imagecolorallocatealpha($im, ($tcr * $ya + $icr * $yb), ($tcg * $ya + $icg * $yb), ($tcb * $ya + $icb * $yb), $alpha));
  42. $trgb = ImageColorAt($im, $x, ceil($y));
  43. $tcr = ($trgb >> 16) & 0xFF;
  44. $tcg = ($trgb >> 8) & 0xFF;
  45. $tcb = $trgb & 0xFF;
  46. imagesetpixel($im, $x, ceil($y), imagecolorallocatealpha($im, ($tcr * $yb + $icr * $ya), ($tcg * $yb + $icg * $ya), ($tcb * $yb + $icb * $ya), $alpha));
  47. $x++;
  48. }
  49. } else {
  50. $y = min($y1, $y2);
  51. $endy = max($y1, $y2) + 1;
  52. while ($y < $endy) {
  53. $x = ($y - $b) / $m;
  54. $xa = ($x == floor($x) ? 1: $x - floor($x));
  55. $xb = ceil($x) - $x;
  56. $trgb = ImageColorAt($im, floor($x), $y);
  57. $tcr = ($trgb >> 16) & 0xFF;
  58. $tcg = ($trgb >> 8) & 0xFF;
  59. $tcb = $trgb & 0xFF;
  60. imagesetpixel($im, floor($x), $y, imagecolorallocatealpha($im, ($tcr * $xa + $icr * $xb), ($tcg * $xa + $icg * $xb), ($tcb * $xa + $icb * $xb), $alpha));
  61. $trgb = ImageColorAt($im, ceil($x), $y);
  62. $tcr = ($trgb >> 16) & 0xFF;
  63. $tcg = ($trgb >> 8) & 0xFF;
  64. $tcb = $trgb & 0xFF;
  65. imagesetpixel ($im, ceil($x), $y, imagecolorallocatealpha($im, ($tcr * $xb + $icr * $xa), ($tcg * $xb + $icg * $xa), ($tcb * $xb + $icb * $xa), $alpha));
  66. $y ++;
  67. }
  68. }
  69. }
  70. return $im;
  71. } // end of 'imageSmoothAlphaLine()' function
  72. ?>