Skip to main content
The Laravel QR Code package supports three color models — RGB, CMYK, and grayscale — plus gradients and individual per-eye color overrides. Every color method is chainable, so you can combine them freely before calling generate().

RGB (Default)

RGB is the default color model. Pass red, green, and blue values on a 0–255 scale to color() and backgroundColor().
use Linkxtr\QrCode\Facades\QrCode;

// Red foreground, white background
QrCode::color(220, 38, 38)
    ->backgroundColor(255, 255, 255)
    ->generate('https://example.com');

RGB with Alpha

Add a fourth argument to include an alpha (transparency) channel. The scale is 0–100, where 0 is fully opaque and 100 is fully transparent.
// 50 % transparent foreground on a transparent background
QrCode::color(220, 38, 38, 50)
    ->backgroundColor(255, 255, 255, 0)
    ->generate('https://example.com');
Alpha values use a 0–100 scale, not the 0–255 scale you may be used to from CSS or image editors. The package converts this to the correct internal representation automatically.

CMYK

Switch to CMYK mode by calling cmyk() before color(). All four channel values use a 0–100 scale (percentage).
// Call cmyk() first, then set C / M / Y / K values
QrCode::cmyk()
    ->color(0, 100, 100, 0)      // pure red in CMYK
    ->backgroundColor(0, 0, 0, 0) // white in CMYK
    ->generate('https://example.com');
Gradients are only available in RGB mode. Calling gradient() while in CMYK mode is not supported.
You can switch back to RGB at any point by calling rgb().
QrCode::cmyk()
    ->color(100, 50, 0, 10)
    ->rgb() // switch back to RGB for the background
    ->backgroundColor(255, 255, 255)
    ->generate('https://example.com');

Grayscale

Use gray() for a one-call shorthand that sets both foreground and (optionally) background to shades of gray. The scale is 0–100, where 0 is black and 100 is white.
// Dark gray foreground, light gray background
QrCode::gray(20, 90)->generate('https://example.com');

// Black foreground, white background (defaults)
QrCode::gray(0)->generate('https://example.com');
  • First argument — foreground shade (0 = black, 100 = white).
  • Second argument — background shade. Defaults to 100 (white) when omitted.

Gradients

Apply a two-color gradient to the QR code foreground with gradient(). Provide start and end colors as RGB arrays or hex strings, then choose a direction.
// Vertical gradient: blue → red
QrCode::gradient([0, 0, 255], [255, 0, 0], 'vertical')
    ->generate('https://example.com');

// Horizontal gradient: green → purple
QrCode::gradient([34, 197, 94], [168, 85, 247], 'horizontal')
    ->generate('https://example.com');

// Diagonal gradient
QrCode::gradient([255, 165, 0], [255, 0, 128], 'diagonal')
    ->generate('https://example.com');

Gradient Types

ValueDirection
verticalTop to bottom
horizontalLeft to right
diagonalTop-left to bottom-right
inverse_diagonalTop-right to bottom-left
radialRadiates outward from the center
Gradients are only available in RGB mode. Using gradient() after calling cmyk() is not supported.

Per-Eye Color Overrides

Override the color of any individual eye with eyeColor(). Each QR code has three positional eyes indexed 0, 1, and 2.
// eyeColor(index, innerColor, outerColor)
QrCode::eyeColor(0, [220, 38, 38], [30, 64, 175])  // eye 0: red inner, blue outer
    ->eyeColor(1, [22, 163, 74], [126, 34, 206])    // eye 1: green inner, purple outer
    ->eyeColor(2, [245, 158, 11], [15, 118, 110])   // eye 2: amber inner, teal outer
    ->generate('https://example.com');
  • Index0 (top-left), 1 (top-right), 2 (bottom-left).
  • Inner color — color of the small inner marker square.
  • Outer color — color of the outer frame. Omit this argument to apply the inner color to both parts.
// Same color for both inner and outer parts of eye 0
QrCode::eyeColor(0, [220, 38, 38])->generate('https://example.com');
Custom eye colors require the ext-imagick PHP extension when generating raster formats like PNG. The GD fallback supports the default foreground color only — calling eyeColor() without Imagick installed throws a MissingExtensionException. SVG and EPS output are unaffected and work without Imagick.

Complete Color Example

Chain color options with style and format options to build a fully branded QR code.
use Linkxtr\QrCode\Facades\QrCode;

$qr = QrCode::format('png')
    ->size(400)
    ->style('dot')
    ->eye('circle')
    ->gradient([99, 102, 241], [236, 72, 153], 'diagonal')
    ->backgroundColor(255, 255, 255)
    ->eyeColor(0, [99, 102, 241], [30, 27, 75])
    ->eyeColor(1, [99, 102, 241], [30, 27, 75])
    ->eyeColor(2, [99, 102, 241], [30, 27, 75])
    ->generate('https://example.com');

Styling

Set module shape, eye style, size, margin, and output format.

Image Merge

Embed a logo or image into the center of your QR code.