QRInterventionImage.md.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # QRInterventionImage
  2. [Class `QRInterventionImage`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRInterventionImage.php):
  3. [intervention/image](https://image.intervention.io/) alternative GD/ImageMagick output.
  4. ***Note:** this output class works significantly slower than the native GD/Imagick output classes due to the several underlying abstraction layers. Use only if you must.*
  5. ## Example
  6. See: [intervention/image example](https://github.com/chillerlan/php-qrcode/blob/main/examples/intervention-image.php)
  7. Set the options:
  8. ```php
  9. $options = new QROptions;
  10. $options->outputInterface = QRInterventionImage::class;
  11. $options->scale = 20;
  12. $options->bgColor = '#ccccaa';
  13. $options->imageTransparent = false;
  14. $options->transparencyColor = '#ccccaa';
  15. $options->drawLightModules = false;
  16. $options->drawCircularModules = true;
  17. $options->circleRadius = 0.4;
  18. $options->keepAsSquare = [
  19. QRMatrix::M_FINDER_DARK,
  20. QRMatrix::M_FINDER_DOT,
  21. QRMatrix::M_ALIGNMENT_DARK,
  22. ];
  23. $options->moduleValues = [
  24. QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
  25. QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
  26. QRMatrix::M_FINDER => '#FFBFBF', // light (false)
  27. QRMatrix::M_ALIGNMENT_DARK => '#A70364',
  28. QRMatrix::M_ALIGNMENT => '#FFC9C9',
  29. QRMatrix::M_VERSION_DARK => '#650098',
  30. QRMatrix::M_VERSION => '#E0B8FF',
  31. ];
  32. ```
  33. Render the output:
  34. ```php
  35. $data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
  36. $out = (new QRCode($options))->render($data); // -> data:image/png;base64,...
  37. printf('<img alt="%s" src="%s" />', $alt, $out);
  38. ```
  39. Return the `ImageInterface` instance (will ignore other output options):
  40. ```php
  41. $options->returnResource = true;
  42. /** @var \Intervention\Image\Interfaces\ImageInterface $image */
  43. $image = (new QRCode($options))->render($data);
  44. // do stuff with the ImageInterface instance...
  45. // ...dump output
  46. header('Content-type: image/png');
  47. echo $image->toPng()->toString();
  48. ```
  49. Set a different driver in the internal `ImageManager` instance (the internal detection order is: 1. GD, 2. Imagick):
  50. ```php
  51. $qrOutputInterface = new QRInterventionImage($options, $matrix);
  52. // set a different driver
  53. $qrOutputInterface->setDriver(new \Intervention\Image\Drivers\Imagick\Driver);
  54. // dump output
  55. $out = $qrOutputInterface->dump();
  56. ```
  57. ## Additional methods
  58. | method | return | description |
  59. |--------------------------------------|----------|----------------------------------------------------------------------------------------------------------------------|
  60. | `setDriver(DriverInterface $driver)` | `static` | Sets a DriverInterface, see [instantiation (intervention.io)](https://image.intervention.io/v3/basics/instantiation) |
  61. | (protected) `module()` | `void` | Draws a single pixel at the given position |
  62. ## Options that affect this class
  63. | property | type |
  64. |------------------------|----------|
  65. | `$bgColor` | `mixed` |
  66. | `$circleRadius` | `float` |
  67. | `$drawCircularModules` | `bool` |
  68. | `$drawLightModules` | `bool` |
  69. | `$imageTransparent` | `bool` |
  70. | `$keepAsSquare` | `array` |
  71. | `$outputBase64` | `bool` |
  72. | `$returnResource` | `bool` |
  73. | `$scale` | `int` |
  74. | `$transparencyColor` | `mixed` |