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()

Set the foreground (module) color. The meaning of each channel depends on the active color model.
int
required
RGB mode: Red channel, 0–255. CMYK mode: Cyan channel, 0–100.
int
required
RGB mode: Green channel, 0–255. CMYK mode: Magenta channel, 0–100.
int
required
RGB mode: Blue channel, 0–255. CMYK mode: Yellow channel, 0–100.
int | null
RGB mode: Alpha channel, 0–100 (0 = fully opaque). CMYK mode: Black (Key) channel, 0–100. Omit for a fully opaque foreground.

backgroundColor()

Set the background color. Accepts the same channel layout as color() and respects the active color model.
int
required
RGB mode: Red, 0–255. CMYK mode: Cyan, 0–100.
int
required
RGB mode: Green, 0–255. CMYK mode: Magenta, 0–100.
int
required
RGB mode: Blue, 0–255. CMYK mode: Yellow, 0–100.
int | null
RGB mode: Alpha, 0–100. CMYK mode: Black, 0–100. Omit for a fully opaque background.

rgb()

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.

cmyk()

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.

gray()

Switch to grayscale mode and set both foreground and background tones in a single call. Internally this sets the color model to GRAY.
int
required
Foreground luminance: 0 = black, 100 = white.
int | null
Background luminance on the same 0–100 scale. When null, the background defaults to white (100).

gradient()

Apply a two-stop color gradient to the QR code modules. Gradient operates in RGB mode only.
string | array
required
The gradient start color. Pass a hex string (e.g. '#3b82f6') or an RGB array (e.g. [59, 130, 246]).
string | array
required
The gradient end color. Accepts the same formats as start.
string
required
The gradient direction. Accepted values:
gradient() takes color values directly rather than using whatever was set by a prior color() call. The gradient replaces the foreground color entirely.

Color model comparison