Skip to content

QR Codes

Short URL generates QR code images for every short URL using the endroid/qr-code PHP library.

Endpoints

QR codes are served at dedicated API routes. All endpoints require the Access content permission.

Endpoint Format Description
/api/shorturl/qr/{slug} Config Default format (PNG/SVG)
/api/shorturl/qr/{slug}/png PNG Raster image
/api/shorturl/qr/{slug}/svg SVG Vector image

The default format is configured in the module settings.

Responses include a 24-hour browser cache header (Cache-Control: max-age=86400). The Content-Disposition header is set to attachment on the PNG and SVG endpoints so browsers offer a file download.

Path shortcut

Appending .qr to any short URL slug serves the QR code in the default format. For example, if your short URL is https://example.com/promo, then https://example.com/promo.qr returns the QR code image.

This is handled by an inbound path processor that rewrites /{slug}.qr to /api/shorturl/qr/{slug}.

Node view display

A Short URL & QR code pseudo-field is available on the Short URL content type's view display. When enabled, it renders:

  • The full short URL as a clickable input field with a copy-to-clipboard button
  • The destination URL
  • An optional label
  • An inline QR code (SVG data URI)
  • Download links for SVG and PNG formats

The pseudo-field can be positioned and toggled via Manage display on the Short URL content type.

QR code settings

Setting Values Description
Error correction Medium Balance between size and recovery
Size 200px / 300px 200px for inline, 300px for downloads
Margin 10px Quiet zone around the QR code
Encoding UTF-8 Character encoding

These values are hardcoded in the QrCodeGenerator service. To customize them, override the service in your site's services.yml:

services:
  Drupal\shorturl\QrCodeGeneratorInterface:
    class: Drupal\my_module\MyQrCodeGenerator