This repository provides a Go program that captures a screenshot of a webpage, generates a QR code for the same URL, and overlays the QR code and the URL text on the screenshot. The final image is saved as a PNG file.
The goal of this project is to demonstrate how to use Go with chromedp
to automate web browsing and screenshot capture. Additionally, it uses the go-qrcode
library to generate a QR code for the webpage URL and overlays both the QR code and the URL text on the captured screenshot.
- Capture a screenshot of a webpage using headless Chrome.
- Generate a QR code for a specified URL.
- Overlay the QR code and URL text on the screenshot.
- Save the final composite image as a PNG file.
To run this program, you will need:
- Go 1.16 or later
- Headless Chrome
- Fonts that support Truetype, like DejaVu Sans or any other Truetype font.
- The following Go packages:
github.com/chromedp/chromedp
github.com/golang/freetype
github.com/golang/freetype/truetype
github.com/skip2/go-qrcode
golang.org/x/image/font
-
Install Go: Ensure you have Go installed on your machine. You can download it from the official Go website.
-
Install Headless Chrome: If you haven't installed Chrome or Chromium yet, you can download it from here or use your package manager.
-
Get the required Go packages: Run the following command to install the necessary Go packages:
go get -u github.com/chromedp/chromedp go get -u github.com/golang/freetype go get -u github.com/skip2/go-qrcode go get -u golang.org/x/image/font
-
Clone the repository:
git clone https://github.com/logerror/url2img.git
cd url2img
- Build the program:
go build -o url2img main.go
Run the compiled binary with:
./url2img <Url> <Image Path: eg: screenshot_with_qrcode.png>
example: ./url2img https://logerror.github.io screenshot_with_qrcode.png
The program will capture a screenshot of the specified URL, generate a QR code, overlay the QR code and the URL text on the screenshot, and save the final image as screenshot_with_qrcode.png.