How to generate a QR code as a PNG file in Ruby

Cloudmersive
1 min readAug 9, 2019

--

Let’s look at how to use a Cloudmersive API to save time in generating QR codes. First up, add this snippet to your Gemfile to install the API client.

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

Then run the generate_barcode_qr_code function, as you see here.

# 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 a PNG file, a type of 2D barcode which can encode free-form text information
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

Annnnd we’re done. Your output will be a PNG of your QR code. If you work with other types of barcodes, we have separate functions in this API that generate the most popular formats.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet