Project

qr_forge

0.0
No release in over 3 years
QRForge is a Ruby gem for rendering QR codes with different designs and formats.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 3.40

Runtime

~> 0.3.0
~> 1.18
~> 2.6
 Project Readme

output

An example of the output of QR Forge

QR Forge

This library is a QR Code renderer that lets you customize almost every aspect of a QR Code. From module design to a logo, this library is meant to be design-extensible, which means you can render your own components such as modules, the outer eyes and inner eyes etc. in your own custom SVG shapes.

Installation

gem install qr_forge

or if using bundler

bundle add qr_forge

Usage

To create a QR Code you can simply do the following:

Payloads

Did you know that QR Codes can store different pieces of data such as wifi access, passkeys, geolocation and quite a few more! Below are a few different types of data payloads that are implemented with in the gem. More will be added as needed.

Plain text

QrForge::Forge.build(data: "https://yourlinkhere.com", type: :plain)

URL

QrForge::Forge.build(data: "https://yourlinkhere.com", type: :url)

Wifi

QrForge::Forge.build(data: { ssid: "MyNetwork", password: "MyPassword", encryption: "WPA" }, type: :wifi)

Fields:

  • ssid,
  • password
  • encryption (WEP WPA WPA2 WPA3)
  • hidden (true/false)

Note

You can also pass "nopass" to encryption which means a password does not need to be provided either (public wifi etc.)

Geo/Coordinates

QrForge::Forge.build(data: { latitude: 40.712776, longitude: -74.005974 }, type: :geo)

Fields:

  • latitude
  • longitude

Phone number

QrForge::Forge.build(data: "+1234567890", type: :phone)
QrForge::Forge.build(data: "1234567890", type: :phone)
QrForge::Forge.build(data: "123-456-7890", type: :phone)
QrForge::Forge.build(data: "(123) 456-7890", type: :phone)
QrForge::Forge.build(data: "123.456.7890", type: :phone)

More are planned to be added.

Design

Design controls the look and feel of the QR Code from the QR Version to the colors of the individual modules.

QR
QrForge::Forge.build(..., design: { qr: { version: 10 } }, ...)

Fields:

  • Version
Image
QrForge::Forge.build(..., design: { image: "..." }, ...)

The image should be a Base64 encoded image like the following:

Base64.strict_encode64(image_png_binary)

More image formats will be added as needed or required.

Note

The size of the image will scale relative to the version of the QR Code (and the SVG width/height for that matter). This is due to how we use the error-correction algorithm for QR Codes to show an image, in other words, the image can only take up so much space before the data becomes unreadable, so you cannot set the size.

Colors
QrForge::Forge.build(..., design: {colors: { outer_eye: "#30363D", inner_eye: "#30363D", module: "#484F58" }, ...)

Fields:

  • outer_eye
  • inner_eye
  • module

Any hex code or plain color such as "red", "cyan", "peru", etc. will work as the color value.

See the Components section for more details on which field references what component of the QR Code.

Output

QrForge::Forge.build(..., output: { size: 250 }, ...)

Fields:

  • size

QR Codes are equal in height and width, the size will control the width and height of the returned SVG.

There is only an ouput of SVG format, see this PR for reasoning: #1

If different formats are a requirement and that requirement means the image conversion should take place in the gem, send me a message with your usecase. SVG as the format should be good for almost all usecases.

Components

QrForge::Forge.build(..., components: {
                              outer_eye: QrForge::Components::EyeOuter::Square,
                              inner_eye: QrForge::Components::EyeInner::Square,
                              module: QrForge::Components::Module::Square
                            },
                        ...)

Fields:

  • outer_eye
Screenshot 2025-06-17 at 1 23 39 AM
  • inner_eye
Screenshot 2025-06-17 at 1 24 22 AM
  • module
Screenshot 2025-06-17 at 1 25 24 AM

You can create your own designs and pass them through as long as they inherit from the ForgeComponent. If you create your own designs, when you pass them through the config, it will merge them with the default components, so if you only want to change one or two of the components, but not all three, you can!

Note

More designs are to come, so not every facet of qr code manipulation may be available at this time such as module look aheads/behinds. This is >coming soon.

Example

This is the code that was used to create the QR Code at the top of the page.

image = Base64.strict_encode64(Base64.strict_encode64(File.binread("logo-github.png"))
QrForge::Forge.build(data: "https://www.github.com/keegankb93/qr_forge",
                     type: :url,
                     config: {
                       qr: { version: 5 },
                       design: {
                         image:,
                         colors: {
                           outer_eye: "#30363D",
                           inner_eye: "#30363D",
                           module: "#484F58"
                         }
                       },
                       output: { size: 250 }
                     })

Roadmap

  • Color gradients for outer and inner eyes
  • Image background and shape improvements
  • More default component selections