QRImagick.md.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # QRImagick
  2. [Class `QRImagick`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRImagick.php): [ImageMagick](https://www.php.net/manual/book.imagick) output, [multiple supported image formats](https://imagemagick.org/script/formats.php)
  3. Please follow the installation guides for your operating system:
  4. - ImageMagick: [imagemagick.org/script/download.php](https://imagemagick.org/script/download.php)
  5. - PHP `ext-imagick`: [github.com/Imagick/imagick](https://github.com/Imagick/imagick) ([Windows downloads](https://mlocati.github.io/articles/php-windows-imagick.html))
  6. - [PHP Imagick by Example](https://phpimagick.com/) ([github.com/Imagick/ImagickDemos](https://github.com/Imagick/ImagickDemos))
  7. ## Example
  8. See: [ImageMagick example](https://github.com/chillerlan/php-qrcode/blob/main/examples/imagick.php)
  9. Set the options:
  10. ```php
  11. $options = new QROptions;
  12. $options->outputInterface = QRImagick::class;
  13. $options->imagickFormat = 'webp'; // e.g. png32, jpeg, webp
  14. $options->quality = 90;
  15. $options->scale = 20;
  16. $options->bgColor = '#ccccaa';
  17. $options->imageTransparent = true;
  18. $options->transparencyColor = '#ccccaa';
  19. $options->drawLightModules = true;
  20. $options->drawCircularModules = true;
  21. $options->circleRadius = 0.4;
  22. $options->keepAsSquare = [
  23. QRMatrix::M_FINDER_DARK,
  24. QRMatrix::M_FINDER_DOT,
  25. QRMatrix::M_ALIGNMENT_DARK,
  26. ];
  27. $options->moduleValues = [
  28. QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
  29. QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
  30. QRMatrix::M_FINDER => '#FFBFBF', // light (false)
  31. QRMatrix::M_ALIGNMENT_DARK => '#A70364',
  32. QRMatrix::M_ALIGNMENT => '#FFC9C9',
  33. QRMatrix::M_VERSION_DARK => '#650098',
  34. QRMatrix::M_VERSION => '#E0B8FF',
  35. ];
  36. ```
  37. Render the output:
  38. ```php
  39. $data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
  40. $out = (new QRCode($options))->render($data); // -> data:image/webp;base64,...
  41. printf('<img alt="%s" src="%s" />', $alt, $out);
  42. ```
  43. Return the `Imagick` instance (will ignore other output options):
  44. ```php
  45. $options->returnResource = true;
  46. /** @var \Imagick $imagick */
  47. $imagick = (new QRCode($options))->render($data);
  48. // do stuff with the Imagick instance...
  49. $imagick->scaleImage(150, 150, true);
  50. // ...
  51. // ...dump output
  52. $imagick->setImageFormat('png32');
  53. header('Content-type: image/png');
  54. echo $imagick->getImageBlob();
  55. ```
  56. ## Additional methods
  57. | method | return | description |
  58. |--------------------------------------|--------|--------------------------------------------|
  59. | (protected) `drawImage()` | `void` | Creates the QR image via ImagickDraw |
  60. | (protected) `module()` | `void` | Draws a single pixel at the given position |
  61. | (protected) `setBgColor()` | `void` | Sets the background color |
  62. | (protected) `setTransparencyColor()` | `void` | Sets the transparency color |
  63. ## Options that affect this class
  64. | property | type |
  65. |------------------------|----------|
  66. | `$bgColor` | `mixed` |
  67. | `$circleRadius` | `float` |
  68. | `$drawCircularModules` | `bool` |
  69. | `$drawLightModules` | `bool` |
  70. | `$imageTransparent` | `bool` |
  71. | `$imagickFormat` | `string` |
  72. | `$keepAsSquare` | `array` |
  73. | `$outputBase64` | `bool` |
  74. | `$quality` | `int` |
  75. | `$returnResource` | `bool` |
  76. | `$scale` | `int` |
  77. | `$transparencyColor` | `mixed` |