Skip to main content
The package supports three color models — RGB (default), CMYK, and grayscale. Switch between them at any point in the builder chain. Every method returns a cloned Generator so previous state is never mutated.
Alpha values throughout this package use a 0–100 scale (0 = fully opaque, 100 = fully transparent). The package converts this internally to the range PHP’s GD library expects (0–127). You do not need to perform this conversion yourself.

color()

public function color(int $c1, int $c2, int $c3, ?int $c4 = null): static
Set the foreground (module) color. The meaning of each channel depends on the active color model.
c1
int
required
RGB mode: Red channel, 0–255. CMYK mode: Cyan channel, 0–100.
c2
int
required
RGB mode: Green channel, 0–255. CMYK mode: Magenta channel, 0–100.
c3
int
required
RGB mode: Blue channel, 0–255. CMYK mode: Yellow channel, 0–100.
c4
int | null
RGB mode: Alpha channel, 0–100 (0 = fully opaque). CMYK mode: Black (Key) channel, 0–100. Omit for a fully opaque foreground.
QrCode::color(220, 38, 38)           // solid red
    ->generate('https://example.com');

backgroundColor()

public function backgroundColor(int $c1, int $c2, int $c3, ?int $c4 = null): static
Set the background color. Accepts the same channel layout as color() and respects the active color model.
c1
int
required
RGB mode: Red, 0–255. CMYK mode: Cyan, 0–100.
c2
int
required
RGB mode: Green, 0–255. CMYK mode: Magenta, 0–100.
c3
int
required
RGB mode: Blue, 0–255. CMYK mode: Yellow, 0–100.
c4
int | null
RGB mode: Alpha, 0–100. CMYK mode: Black, 0–100. Omit for a fully opaque background.
QrCode::color(0, 0, 0)
    ->backgroundColor(255, 255, 255)
    ->generate('https://example.com');

rgb()

public function rgb(): static
Switch the active color model to RGB. This is the default mode — call it explicitly only when you need to revert from CMYK in a chain. Each channel uses a 0–255 scale. Alpha uses a 0–100 scale.
QrCode::rgb()
    ->color(59, 130, 246)
    ->generate('https://example.com');

cmyk()

public function cmyk(): static
Switch the active color model to CMYK. All subsequent calls to color() and backgroundColor() interpret channel values on a 0–100 scale (percentage).
Gradients (gradient()) are only available in RGB mode. Calling gradient() while in CMYK mode will produce unexpected results. Switch back to rgb() before using gradients.
QrCode::size(300)
    ->cmyk()
    ->color(100, 50, 0, 10)          // deep blue in CMYK
    ->backgroundColor(0, 0, 0, 0)   // white background in CMYK
    ->generate('https://example.com');

gray()

public function gray(int $gray, ?int $backgroundGray = null): static
Switch to grayscale mode and set both foreground and background tones in a single call. Internally this sets the color model to GRAY.
gray
int
required
Foreground luminance: 0 = black, 100 = white.
backgroundGray
int | null
Background luminance on the same 0–100 scale. When null, the background defaults to white (100).
QrCode::gray(0)->generate('https://example.com');

gradient()

public function gradient(string|array $start, string|array $end, string|GradientType $type = GradientType::VERTICAL): static
Apply a two-stop color gradient to the QR code modules. Gradient operates in RGB mode only.
start
string | array
required
The gradient start color. Pass a hex string (e.g. '#3b82f6') or an RGB array (e.g. [59, 130, 246]).
end
string | array
required
The gradient end color. Accepts the same formats as start.
type
string
required
The gradient direction. Accepted values:
ValueDescription
verticalTop-to-bottom (default)
horizontalLeft-to-right
diagonalTop-left to bottom-right
inverse_diagonalTop-right to bottom-left
radialRadiating from the centre outward
gradient() takes color values directly rather than using whatever was set by a prior color() call. The gradient replaces the foreground color entirely.
QrCode::size(300)
    ->gradient('#3b82f6', '#8b5cf6', 'vertical')
    ->generate('https://example.com');

Color model comparison

use Linkxtr\QrCode\Facades\QrCode;

// Default RGB — channels 0-255, optional alpha 0-100
$rgb = QrCode::color(30, 64, 175)
    ->backgroundColor(239, 246, 255)
    ->generate('https://example.com');

// CMYK — channels 0-100 (percentage)
$cmyk = QrCode::cmyk()
    ->color(83, 64, 0, 31)           // dark blue in CMYK
    ->backgroundColor(0, 0, 0, 0)
    ->generate('https://example.com');

// Grayscale — luminance 0-100
$gray = QrCode::gray(10, 95)->generate('https://example.com');

// Gradient (RGB only)
$gradient = QrCode::gradient('#1e40af', '#7c3aed', 'vertical')
    ->generate('https://example.com');