Set foreground and background colors using RGB, CMYK, or grayscale models. Add gradients and per-eye color overrides for fully branded Laravel QR codes.
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 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 backgroundQrCode::color(220, 38, 38) ->backgroundColor(255, 255, 255) ->generate('https://example.com');
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 backgroundQrCode::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.
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 valuesQrCode::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');
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 backgroundQrCode::gray(20, 90)->generate('https://example.com');// Black foreground, white background (defaults)QrCode::gray(0)->generate('https://example.com');
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.
Index — 0 (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 0QrCode::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.