Ruby QR Code Library

Generate QR Codes with Ruby

Ruby's rqrcode gem makes QR code generation simple and elegant. Perfect for Rails applications, scripts, and automation workflows.

Installation

Install the rqrcode gem using Bundler or gem install.

Gemfile
gem 'rqrcode'
gem
gem install rqrcode

Generate QR Codes with rqrcode

Code examples using the rqrcode gem in Ruby.

QR Code as SVG
require 'rqrcode'

qr = RQRCode::QRCode.new('https://qrcode.fun')

svg = qr.as_svg(
  offset: 0,
  color: '1A2B3C',
  shape_rendering: 'crispEdges',
  module_size: 6,
  standalone: true
)

File.write('qrcode.svg', svg)
QR Code as PNG
require 'rqrcode'

qr = RQRCode::QRCode.new('https://qrcode.fun')

png = qr.as_png(
  bit_depth: 1,
  border_modules: 4,
  color_mode: ChunkyPNG::COLOR_GRAYSCALE,
  color: 'black',
  file: nil,
  fill: 'white',
  module_px_size: 6,
  resize_exactly_to: false,
  resize_gte_to: false,
  size: 300
)

IO.binwrite('qrcode.png', png.to_s)
Rails Controller
class QrCodesController < ApplicationController
  def show
    qr = RQRCode::QRCode.new(params[:data] || 'https://qrcode.fun')
    svg = qr.as_svg(module_size: 6, standalone: true)

    render inline: svg, content_type: 'image/svg+xml'
  end
end
QRCode.fun API

Generate QR Codes via API in Ruby

Call the QRCode.fun API from Ruby using Net::HTTP or Faraday for styled QR codes.

Ruby API Integration
require 'net/http'
require 'json'

uri = URI('https://qrcode.fun/api/generate-qr-styled')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request.body = {
  data: 'https://qrcode.fun',
  width: 300,
  height: 300,
  type: 'png',
  margin: 10,
  dotsOptions: { color: '#1A2B3C', type: 'rounded' },
  cornersSquareOptions: { color: '#8564C3', type: 'extra-rounded' },
  backgroundOptions: { color: '#FFFFFF' }
}.to_json

response = http.request(request)
result = JSON.parse(response.body)
puts result['data'][0..49]

Live QR Code Preview

Try generating a QR code with Ruby right now.

QR preview

Native Library vs API

Compare using rqrcode versus the QRCode.fun API.

Featurerqrcode GemQRCode.fun API
Setup complexitygem install + ChunkyPNG for imagesSingle HTTP request
CustomizationColors, module size (SVG/PNG)Full styling: colors, shapes, logos
Offline supportYesRequires internet
Maintenancebundle updateAlways up-to-date
Output formatsSVG, PNG, ANSI terminalPNG, SVG

Ruby QR Code Use Cases

Common scenarios for QR codes in Ruby applications.

Rails Applications

Generate QR codes in Rails controllers for user profiles, event tickets, and two-factor authentication setup.

Background Jobs

Create QR codes asynchronously with Sidekiq or Active Job for batch label generation and email campaigns.

API Endpoints

Build API endpoints that return QR codes as images or SVG for mobile apps and third-party integrations.

Automation Scripts

Write Ruby scripts for generating QR codes in bulk for inventory, asset tagging, and event management.

Frequently Asked Questions

Common questions about generating QR codes with Ruby.

rqrcode is the most popular and well-maintained Ruby gem for QR code generation. It supports SVG and PNG output and integrates well with Rails.

Start generating QR codes with Ruby

Use our free generator or integrate the API into your Ruby and Rails applications.