QROptions.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. /**
  3. * Class QROptions
  4. *
  5. * @filesource QROptions.php
  6. * @created 08.12.2015
  7. * @package chillerlan\QRCode
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2015 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCode;
  13. use chillerlan\QRCode\Data\QRMatrix;
  14. use chillerlan\Traits\{
  15. Container, ContainerInterface
  16. };
  17. /**
  18. * @property int $version
  19. * @property int $versionMin
  20. * @property int $versionMax
  21. * @property int $eccLevel
  22. * @property int $maskPattern
  23. * @property bool $addQuietzone
  24. * @property bool $quietzoneSize
  25. *
  26. * @property string $outputType
  27. * @property string $outputInterface
  28. * @property string $cachefile
  29. *
  30. * @property string $eol
  31. * @property int $scale
  32. *
  33. * @property string $cssClass
  34. * @property string $svgOpacity
  35. * @property string $svgDefs
  36. *
  37. * @property string $textDark
  38. * @property string $textLight
  39. *
  40. * @property bool $imageBase64
  41. * @property bool $imageTransparent
  42. * @property array $imageTransparencyBG
  43. * @property int $pngCompression
  44. * @property int $jpegQuality
  45. *
  46. * @property array $moduleValues
  47. */
  48. class QROptions implements ContainerInterface{
  49. use Container;
  50. /**
  51. * QR Code version number
  52. *
  53. * [1 ... 40] or QRCode::VERSION_AUTO
  54. *
  55. * @var int
  56. */
  57. protected $version = QRCode::VERSION_AUTO;
  58. /**
  59. * Minimum QR version (if $version = QRCode::VERSION_AUTO)
  60. *
  61. * @var int
  62. */
  63. protected $versionMin = 1;
  64. /**
  65. * Maximum QR version
  66. *
  67. * @var int
  68. */
  69. protected $versionMax = 40;
  70. /**
  71. * Error correct level
  72. *
  73. * QRCode::ECC_X where X is
  74. * L => 7%
  75. * M => 15%
  76. * Q => 25%
  77. * H => 30%
  78. *
  79. * @var int
  80. */
  81. protected $eccLevel = QRCode::ECC_L;
  82. /**
  83. * Mask Pattern to use
  84. *
  85. * [0...7] or QRCode::MASK_PATTERN_AUTO
  86. *
  87. * @var int
  88. */
  89. protected $maskPattern = QRCode::MASK_PATTERN_AUTO;
  90. /**
  91. * Add a "quiet zone" (margin) according to the QR code spec
  92. *
  93. * @var bool
  94. */
  95. protected $addQuietzone = true;
  96. /**
  97. * Size of the quiet zone
  98. *
  99. * internally clamped to [0 ... $moduleCount / 2], defaults to 4 modules
  100. *
  101. * @var int
  102. */
  103. protected $quietzoneSize = 4;
  104. /**
  105. * QRCode::OUTPUT_MARKUP_XXXX where XXXX = HTML, SVG
  106. * QRCode::OUTPUT_IMAGE_XXX where XXX = PNG, GIF, JPG
  107. * QRCode::OUTPUT_STRING_XXXX where XXXX = TEXT, JSON
  108. * QRCode::OUTPUT_CUSTOM
  109. *
  110. * @var string
  111. */
  112. protected $outputType = QRCode::OUTPUT_IMAGE_PNG;
  113. /**
  114. * the FQCN of the custom QROutputInterface if $outputType is set to QRCode::OUTPUT_CUSTOM
  115. *
  116. * @var string
  117. */
  118. protected $outputInterface;
  119. /**
  120. * /path/to/cache.file
  121. *
  122. * @var string
  123. */
  124. protected $cachefile;
  125. /**
  126. * newline string [HTML, SVG, TEXT]
  127. *
  128. * @var string
  129. */
  130. protected $eol = PHP_EOL;
  131. /**
  132. * size of a QR code pixel [SVG, IMAGE_*]
  133. * HTML -> via CSS
  134. *
  135. * @var int
  136. */
  137. protected $scale = 5;
  138. /**
  139. * a common css class
  140. *
  141. * @var string
  142. */
  143. protected $cssClass;
  144. /**
  145. * SVG opacity
  146. *
  147. * @var float
  148. */
  149. protected $svgOpacity = 1.0;
  150. /**
  151. * anything between <defs>
  152. *
  153. * @see https://developer.mozilla.org/docs/Web/SVG/Element/defs
  154. *
  155. * @var string
  156. */
  157. protected $svgDefs = '<style>rect{shape-rendering:crispEdges}</style>';
  158. /**
  159. * string substitute for dark
  160. *
  161. * @var string
  162. */
  163. protected $textDark = '🔴';
  164. /**
  165. * string substitute for light
  166. *
  167. * @var string
  168. */
  169. protected $textLight = '⭕';
  170. /**
  171. * toggle base64 or raw image data
  172. *
  173. * @var bool
  174. */
  175. protected $imageBase64 = true;
  176. /**
  177. * toggle transparency, not supported by jpg
  178. *
  179. * @var bool
  180. */
  181. protected $imageTransparent = true;
  182. /**
  183. * @see imagecolortransparent()
  184. *
  185. * @var array [R, G, B]
  186. */
  187. protected $imageTransparencyBG = [255, 255, 255];
  188. /**
  189. * @see imagepng()
  190. *
  191. * @var int
  192. */
  193. protected $pngCompression = -1;
  194. /**
  195. * @see imagejpeg()
  196. *
  197. * @var int
  198. */
  199. protected $jpegQuality = 85;
  200. /**
  201. * Module values map
  202. *
  203. * HTML : #ABCDEF, cssname, rgb(), rgba()...
  204. * IMAGE: [63, 127, 255] // R, G, B
  205. *
  206. * @var array
  207. */
  208. protected $moduleValues = [
  209. // light
  210. QRMatrix::M_DATA => false, // 4
  211. QRMatrix::M_FINDER => false, // 6
  212. QRMatrix::M_SEPARATOR => false, // 8
  213. QRMatrix::M_ALIGNMENT => false, // 10
  214. QRMatrix::M_TIMING => false, // 12
  215. QRMatrix::M_FORMAT => false, // 14
  216. QRMatrix::M_VERSION => false, // 16
  217. QRMatrix::M_QUIETZONE => false, // 18
  218. QRMatrix::M_TEST => false, // 255
  219. // dark
  220. QRMatrix::M_DARKMODULE << 8 => true, // 512
  221. QRMatrix::M_DATA << 8 => true, // 1024
  222. QRMatrix::M_FINDER << 8 => true, // 1536
  223. QRMatrix::M_ALIGNMENT << 8 => true, // 2560
  224. QRMatrix::M_TIMING << 8 => true, // 3072
  225. QRMatrix::M_FORMAT << 8 => true, // 3584
  226. QRMatrix::M_VERSION << 8 => true, // 4096
  227. QRMatrix::M_TEST << 8 => true, // 65280
  228. ];
  229. }