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.
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)
To start the application, run the following command:
go run main.go
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