Laravel for Rust Alpha
laravel-rust-qrcode
QR codes for routes, templates, and files.
Serve a QR image from a Laravel route, put it in a MiniJinja view, or render it with the standalone Rust core. The encoder and renderers are checked against fixtures produced by Simple QrCode 4.2.0.
Read the docs Source on GitHub
cargo add laravel-rust-qrcode@0.1.0- Latest release
- 0.1.0, 2026-12-04
- Maintenance
- Active
- Framework
- laravel-rust 0.2.x
- MSRV
- Rust 1.99 or later
- Licence
- MIT
SVG, PNG, and EPS
Set the size, quiet zone, and colors for any of the three formats. PNG works without Imagick. Gradients, module styles, finder options, and logo merges are planned.
Laravel routes and views
Use
Generator::responsein a route or register the service provider for inline SVG and PNG data URIs in MiniJinja.Payload helpers
Build QR payloads for email, geographic coordinates, phone calls, SMS, Wi-Fi, and Bitcoin.
PHP parity
Follows simplesoftwareio/simple-qrcode 4.2.0 (commit 916db7948ca6). Last verified .
- Parity level
- Core
- Abilities
- 50
- Covered
- 13
- Diverged
- 19
- Planned
- 18
- PHP fixtures
- 83
Fixtures are generated by PHP itself: PHP 8.4, bacon/bacon-qr-code 2.0.8, dasprid/enum 1.0.7, simplesoftwareio/simple-qrcode 4.2.0.
Coverage by ability
-
generate· Covered · Core · 1 testGenerator::generate and Writer defaults -
generate.file· Covered · 1 testGenerator::generate with filename -
format.svg· Covered · Core · 1 testGenerator::format('svg') -
format.png· Covered · Core · 1 testGenerator::format('png') -
format.eps· Covered · 1 testGenerator::format('eps') -
format.invalid· Covered · 1 testGenerator::format validation -
size· Diverged · CoreGenerator::size -
margin· Diverged · CoreGenerator::margin -
correction· Covered · Core · 2 testsGenerator::errorCorrection -
encoding· DivergedGenerator::encoding -
matrix.auto· Diverged · CoreWriter automatic encoding policy -
color.foreground· DivergedGenerator::color -
color.background· DivergedGenerator::backgroundColor -
color.create· DivergedGenerator::createColor -
gradient· PlannedGenerator::gradient -
style· PlannedGenerator::style -
eye· PlannedGenerator::eye -
eye.color· PlannedGenerator::eyeColor -
merge.file· PlannedGenerator::merge -
merge.bytes· PlannedGenerator::mergeString -
merge.format· PlannedGenerator PNG-only merge -
image.decode· PlannedImage::__construct -
image.width· PlannedImage::getWidth -
image.height· PlannedImage::getHeight -
image.get· PlannedImage::getImageResource -
image.set· PlannedImage::setImageResource -
image.merge.new· PlannedImageMerge::__construct -
image.merge· PlannedImageMerge::merge -
renderer.writer· Covered · 1 testGenerator::getWriter -
renderer.get· Covered · 1 testGenerator::getRenderer -
renderer.style· PlannedGenerator::getRendererStyle -
renderer.format· DivergedGenerator::getFormatter -
renderer.module· PlannedGenerator::getModule -
renderer.eye· PlannedGenerator::getEye -
renderer.fill· PlannedGenerator::getFill -
helper.email· DivergedGenerator::email and Email -
helper.geo· DivergedGenerator::geo and Geo -
helper.phone· Covered · 1 testGenerator::phoneNumber and PhoneNumber -
helper.sms· DivergedGenerator::SMS and SMS -
helper.wifi· DivergedGenerator::wiFi and WiFi -
helper.btc· DivergedGenerator::BTC and BTC -
helper.dispatch· DivergedGenerator::__call and DataTypeInterface -
laravel.provider.register· DivergedQrCodeServiceProvider::register and Composer discovery -
laravel.provider.provides· DivergedQrCodeServiceProvider::provides -
laravel.facade· Covered · 1 testQrCode facade alias and cache clear -
laravel.html· Covered · Core · 1 testGenerator::generate HtmlString and documented Blade use -
laravel.image· Covered · 1 testDocumented email embed and base64 PNG -
encoding.shift-jis· DivergedBacon Shift-JIS dispatch and aliases -
encoding.invalid· DivergedUnknown and nonexistent encoding labels -
generate.text· DivergedUTF-8 input to the PHP writer
Differences from PHP (19)
Generator::size- The canvas is bounded to 4096 pixels or points, and PNG needs at least one pixel per module. PHP delegates invalid and resource-intensive dimensions to the backend.
Generator::margin- The margin is nonnegative and capped at 64 modules per side before rendering. PHP forwards the raw integer to the backend.
Generator::encoding- Rust supports the listed character sets except nonexistent ISO-8859-12. Its converters follow Unicode mappings that can accept extensions PHP iconv rejects, such as EUC-KR extensions and Windows-1252 C1 controls. The parser also rejects labels outside the listed set, including BIG5.
Writer automatic encoding policy- The Rust encoder can choose a smaller fitting version or a different standard mask. Controlled version and mask reproduce the PHP modules when the encoded bytes, mode, ECI, and error-correction level match. An independent decoder recovers the same bytes.
Generator::color- SVG and PNG support alpha. EPS composites partial alpha onto white. PHP can instead discard alpha or fail while converting an alpha-wrapped black to CMYK.
Generator::backgroundColor- SVG and PNG support alpha. EPS composites partial alpha onto white. PHP can instead discard alpha or fail while converting an alpha-wrapped black to CMYK.
Generator::createColor- The native color type takes RGB and alpha bytes. PHP uses RGB bytes with an optional 0–100 opacity percentage.
Generator::getFormatter- Rust exposes the format and the renderer can use it with any encoded matrix. It does not expose a Bacon-compatible mutable backend.
Generator::email and Email- Recipients must be ASCII mailboxes with a dotted domain. Reserved characters in the address are percent-encoded instead of being copied into the URI.
Generator::geo and Geo- The helper rejects coordinates outside the finite geographic range and emits decimal notation where PHP may emit scientific notation.
Generator::SMS and SMS- The SMS body is percent-encoded after a question mark in the URI, so special characters remain in the body.
Generator::wiFi and WiFi- Wi-Fi values escape field delimiters, hidden flags are spelled true or false, and the payload ends with a doubled semicolon.
Generator::BTC and BTC- Bitcoin amounts use decimal strings and an empty option set omits the question mark.
Generator::__call and DataTypeInterface- Typed Rust functions replace PHP magic method dispatch. Callers with custom payloads pass the text directly to the encoder.
QrCodeServiceProvider::register and Composer discovery- Laravel for Rust applications explicitly add the provider. PHP auto-discovers the provider through Composer.
QrCodeServiceProvider::provides- The Rust provider registers an injectable factory. It uses no PHP string binding or provider service list.
Bacon Shift-JIS dispatch and aliases- Both Shift-JIS spellings select the same policy. Eligible text uses Kanji mode and other text carries ECI 20 in byte mode, fixing Bacon 2.0.8 mode detection and missing ECI.
Unknown and nonexistent encoding labels- The typed parser rejects unavailable character sets up front, including ISO-8859-12. PHP can accept these names with numeric or alphanumeric data because it bypasses conversion for those modes.
UTF-8 input to the PHP writer- The text API takes valid UTF-8 by type. The separate binary API encodes opaque bytes without text conversion.
In practice
Generate a PNG
Encode a URL and leave a four-module quiet zone for scanning.
use laravel_rust_qrcode::{Format, Generator};
fn main() -> Result<(), laravel_rust_qrcode::Error> {
let code = Generator::new()
.format(Format::Png)
.size(174)
.margin(4)
.generate("https://example.test/")?;
println!("{} ({} bytes)", code.content_type(), code.as_bytes().len());
Ok(())
}Built on
- Simple QrCode: The QR code builder this package ports: formats, styling, logos, payload helpers and Laravel integration, following version 4.2.0.
Crates: laravel-rust-qrcode, laravel-rust-qrcode-core
· Upstream notices
Documentation
- OverviewGenerate SVG, PNG, and EPS QR codes for Laravel routes, MiniJinja views, and local files.
- Getting startedInstall the Rust QR code package, render a PNG, and register its Laravel route and template helpers.
- Migrating from PHPFind the Rust equivalents of Simple QrCode methods and see where QR encoding, rendering, and payloads behave differently.
- PHP paritySee how the Rust port checks its payloads, QR module matrices, and rendering against the PHP release.
- ChangelogWhat changed in each release of laravel-rust-qrcode: additions, changes and fixes.