custom_output.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. *
  4. * @filesource custom_output.php
  5. * @created 24.12.2017
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2017 Smiley
  8. * @license MIT
  9. */
  10. use chillerlan\QRCode\{QRCode, QROptions};
  11. use chillerlan\QRCode\Output\QROutputAbstract;
  12. require_once __DIR__.'/../vendor/autoload.php';
  13. class MyCustomOutput extends QROutputAbstract{
  14. protected function setModuleValues():void{
  15. // TODO: Implement setModuleValues() method.
  16. }
  17. public function dump(?string $file = null){
  18. $output = '';
  19. for($row = 0; $row < $this->moduleCount; $row++){
  20. for($col = 0; $col < $this->moduleCount; $col++){
  21. $output .= (int)$this->matrix->check($col, $row);
  22. }
  23. $output .= PHP_EOL;
  24. }
  25. return $output;
  26. }
  27. }
  28. // invoke the QROutputInterface manually
  29. $options = new QROptions([
  30. 'version' => 5,
  31. 'eccLevel' => QRCode::ECC_L,
  32. ]);
  33. $qrOutputInterface = new MyCustomOutput($options, (new QRCode($options))->getMatrix('https://www.youtube.com/watch?v=dQw4w9WgXcQ'));
  34. echo '<pre>'.$qrOutputInterface->dump().'</pre>';
  35. // or just
  36. $options = new QROptions([
  37. 'version' => 5,
  38. 'eccLevel' => QRCode::ECC_L,
  39. 'outputType' => QRCode::OUTPUT_CUSTOM,
  40. 'outputInterface' => MyCustomOutput::class,
  41. ]);
  42. echo '<pre>'.(new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ').'</pre>';