Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How can I add custom colors to the QR code in Laravel
    Laravel QR Code custom QR code colors QR code foreground color QR code background color QR code gradient effect QrCode class Laravel


How can I add custom colors to the QR code in Laravel


To add custom colors to the QR code in Laravel, you can use the `color` method provided by the `QrCode` class. This method allows you to specify the color of the QR code. Here are some examples:

1. Foreground Color:
- You can change the foreground color of the QR code by using the `color` method. For example:

php
     $qrCode = QrCode::size(200)->color(0, 0, 255)->generate('https://example.com');
     

2. Background Color:
- You can change the background color of the QR code by using the `backgroundColor` method. For example:

php
     $qrCode = QrCode::size(200)->backgroundColor(255, 0, 0)->generate('https://example.com');
     

3. Gradient Colors:
- You can create a gradient effect by specifying multiple colors. For example:

php
     $qrCode = QrCode::size(200)
         ->style('dot')
         ->eye('circle')
         ->gradient([255, 0, 0], [0, 0, 255], [0, 0, 0], 'diagonal')
         ->generate('https://example.com');
     

These methods allow you to customize the colors of your QR codes to suit your needs.

Citations:
[1] https://harrk.dev/qr-code-generator-in-laravel-10-tutorial/
[2] https://www.youtube.com/watch?v=OZsKTLoJvEY
[3] https://magecomp.com/blog/generate-qr-code-laravel-9/
[4] https://github.com/Minhazulmin/laravel-10-QR-Code-Generate
[5] https://laracasts.com/discuss/channels/code-review/how-to-add-different-styles-to-qr-code