Generate an EAN-13 Barcode Image in Ruby

Cloudmersive
2 min readJun 23, 2021

--

The EAN-13 barcode is a type of 1D barcode that was developed in Europe, and has become the most commonly used code across the European continent (it is accepted internationally as well). If you create products that are marketed in Europe, it’s a good idea to have an easy system for generating barcodes. By utilizing the following API in Ruby, you will be able to automatically validate and generate an EAN-13 barcode image as a PNG file by simply inputting a barcode value.

Let’s begin by adding the client to our Gemfile:

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

Now we’re ready to call the barcode function with the following example 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 | Barcode value to generate frombegin
#Generate a EAN-13 code barcode as PNG file
result = api_instance.generate_barcode_ean13(value)
p result
rescue CloudmersiveBarcodeApiClient::ApiError => e
puts "Exception when calling GenerateBarcodeApi->generate_barcode_ean13: #{e}"
end

When the process is complete, a new PNG file will be ready for download! If you need to obtain an API key, you can do so by registering for a free account on the Cloudmersive website; this provides 800 calls/month across any of our APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet