https://github.com/settermjd/go-qr-code-generator
This is a small repository showing how to generate a QR code with an optional watermark in Go
https://github.com/settermjd/go-qr-code-generator
Last synced: 11 months ago
JSON representation
This is a small repository showing how to generate a QR code with an optional watermark in Go
- Host: GitHub
- URL: https://github.com/settermjd/go-qr-code-generator
- Owner: settermjd
- Created: 2023-06-13T10:04:54.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-01T20:32:09.000Z (almost 2 years ago)
- Last Synced: 2025-04-09T20:44:04.327Z (about 1 year ago)
- Language: Go
- Size: 14.6 KB
- Stars: 4
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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-url] tutorial on the Twilio blog.
## Prerequisites
To follow along with the tutorial, you don't need much, just the following things:
- [Go][go-url] (a recent version, or the latest, 1.20.5)
- [Curl][curl-url] or [Postman][postman-url]
- 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:
```bash
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_.
```bash
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.
```bash
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
```
[tutorial-url]: https://www.twilio.com/blog/generate-qr-code-with-go
[go-url]: https://go.dev/
[curl-url]: https://curl.se/
[postman-url]: https://www.postman.com/downloads/