ImageBackEndInterface.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types = 1);
  3. namespace BaconQrCode\Renderer\Image;
  4. use BaconQrCode\Exception\RuntimeException;
  5. use BaconQrCode\Renderer\Color\ColorInterface;
  6. use BaconQrCode\Renderer\Path\Path;
  7. use BaconQrCode\Renderer\RendererStyle\Gradient;
  8. /**
  9. * Interface for back ends able to to produce path based images.
  10. */
  11. interface ImageBackEndInterface
  12. {
  13. /**
  14. * Starts a new image.
  15. *
  16. * If a previous image was already started, previous data get erased.
  17. */
  18. public function new(int $size, ColorInterface $backgroundColor) : void;
  19. /**
  20. * Transforms all following drawing operation coordinates by scaling them by a given factor.
  21. *
  22. * @throws RuntimeException if no image was started yet.
  23. */
  24. public function scale(float $size) : void;
  25. /**
  26. * Transforms all following drawing operation coordinates by translating them by a given amount.
  27. *
  28. * @throws RuntimeException if no image was started yet.
  29. */
  30. public function translate(float $x, float $y) : void;
  31. /**
  32. * Transforms all following drawing operation coordinates by rotating them by a given amount.
  33. *
  34. * @throws RuntimeException if no image was started yet.
  35. */
  36. public function rotate(int $degrees) : void;
  37. /**
  38. * Pushes the current coordinate transformation onto a stack.
  39. *
  40. * @throws RuntimeException if no image was started yet.
  41. */
  42. public function push() : void;
  43. /**
  44. * Pops the last coordinate transformation from a stack.
  45. *
  46. * @throws RuntimeException if no image was started yet.
  47. */
  48. public function pop() : void;
  49. /**
  50. * Draws a path with a given color.
  51. *
  52. * @throws RuntimeException if no image was started yet.
  53. */
  54. public function drawPathWithColor(Path $path, ColorInterface $color) : void;
  55. /**
  56. * Draws a path with a given gradient which spans the box described by the position and size.
  57. *
  58. * @throws RuntimeException if no image was started yet.
  59. */
  60. public function drawPathWithGradient(
  61. Path $path,
  62. Gradient $gradient,
  63. float $x,
  64. float $y,
  65. float $width,
  66. float $height
  67. ) : void;
  68. /**
  69. * Ends the image drawing operation and returns the resulting blob.
  70. *
  71. * This should reset the state of the back end and thus this method should only be callable once per image.
  72. *
  73. * @throws RuntimeException if no image was started yet.
  74. */
  75. public function done() : string;
  76. }