How to Generate a QR Code Image in Ruby

Cloudmersive
2 min readMay 17, 2021

--

Over the past year, generating QR codes has proven to be an effective method in creating both a touch-free and technically savvy environment for customers. This form of barcode can facilitate a variety of useful functions such as website displays, text or image displays, and even payments. If you’re looking for a simple way to create a QR code to add to your website, you can use the following API in Ruby to generate a PNG file of a QR code; all you need to provide is the text you want to convert into the barcode!

To start things off, we will add the Ruby client to our Gemfile:

gem 'cloudmersive-barcode-api-client', '~> 2.0.3'

Then we can call the barcode function with the following code:

# load the gem
require 'cloudmersive-barcode-api-client'
# setup authorization
CloudmersiveBarcodeApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
end
api_instance = CloudmersiveBarcodeApiClient::GenerateBarcodeApi.newvalue = 'value_example' # String | QR code text to convert into the QR code barcodebegin
#Generate a QR code barcode as PNG file
result = api_instance.generate_barcode_qr_code(value)
p result
rescue CloudmersiveBarcodeApiClient::ApiError => e
puts "Exception when calling GenerateBarcodeApi->generate_barcode_qr_code: #{e}"
end

This will allow you to easily create QR codes whenever the need arises. To retrieve your API key, head over to the Cloudmersive website to register for a free account; this will provide access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet