Skip to content

This is a small repository showing how to generate a QR code with an optional watermark in Go

Notifications You must be signed in to change notification settings

settermjd/go-qr-code-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generate a QR code in Go

This is a small repository showing how to generate a QR code, with an optional watermark, in Go.

This project is the complete code behind the "How to Generate a QR Code with Go" tutorial on the Twilio blog.

Prerequisites

To follow along with the tutorial, you don't need much, just the following things:

  • Go (a recent version, or the latest, 1.20.5)
  • Curl or Postman
  • A smartphone with a QR code scanner (which, these days, most of them should have)

Start the application

To start the application, run the following command:

go run main.go

Generate a QR code

To generate a QR code, send a POST request to http://localhost:8080/generate with two POST variables:

  • size: This sets the width and height of the QR code
  • url: This is the URL that the QR code will embed

The curl example, below, shows how to create a QR code 256x256 px that embeds "https://arstechnica.com", and outputs the generated QR code to data/qrcode.png.

curl -X POST \
    --form "size=256" \
    --form "url=https://arstechnica.com" \
    --output data/qrcode.png \
    http://localhost:8080/generate

You can also watermark the QR code, by uploading a PNG file using the watermark POST variable. Below is an example of how to do so with curl.

curl -X POST \
    --form "size=256" \
    --form "url=https://matthewsetter.com" \
    --form "watermark=@data/twilio-logo.png" \
    --output data/qrcode.png \
    http://localhost:8080/generate

About

This is a small repository showing how to generate a QR code with an optional watermark in Go

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages