'piping qrencode to eog to avoid creating a file
The following line in the terminal will save a .png image file for a weblink:
qrencode -o qrcode.png 'https://en.wikipedia.org/wiki/Main_Page'
You can then view the qrcode with
eog qrcode.png
How can you pipe the first command into the second and avoid creating a file?
Have tried for example:
qrencode 'https://en.wikipedia.org/wiki/Main_Page' | eog
..but it didn't work.
Solution 1:[1]
How to best create QR Codes in Linux, including Ubuntu:
Summary
Do this:
# 1. 1-line cmd to make a QR code from a URL
qrencode -m 4 -o /tmp/qr.png "www.google.com" \
&& ((eog /tmp/qr.png &); sleep 1; rm /tmp/qr.png)
# 2. 1-line cmd to make a QR code from an entire file
cat "path/to/file.txt" | qrencode -m 4 -o /tmp/qr.png \
&& ((eog /tmp/qr.png &); sleep 1; rm /tmp/qr.png)
Details
I want to point out that there's no real advantage to using feh, so I recommend using eog with temporary files you manually make. feh is a primitive image viewer with no ability to zoom in and out that I can see. Additionally, it uses temporary files anyway, so you're still creating temporary files by using it. If you do this you'll see that:
qrencode -o - 'www.google.com' | feh -
Here is the output. I've highlighted the temporary file path in the image. In this case, it is /tmp/feh_stdin_8WKtoo:
You can even open this image in eog now!:
eog /tmp/feh_stdin_8WKtoo
And eog is a much better viewer, with zoom controls. You can zoom in and out with your mouse wheel.
Use eog
So, you might as well just create your own temporary file and use eog to begin with, like this:
qrencode -o /tmp/qr.png "www.google.com" && ((eog /tmp/qr.png &); sleep 1; \
rm /tmp/qr.png)
The qrencode -o /tmp/qr.png part stores the image into /tmp/qr.png. If that is successful (hence the && part), eog opens that file in the background (&), then we wait a second to ensure eog has finished opening the file (sleep 1;), then we automatically remove it (rm /tmp/qr.png). Done.
Turn an entire text file into a QR code:
# Option 1: multiple lines
filename_to_encode="hello_world.sh"
cat "$filename_to_encode" | qrencode -m 4 -o "/tmp/qrcode.png"
# Use `&` to run in background so that the `rm` cmd next runs **immediately!**
eog "/tmp/qrcode.png" &
sleep 1
rm "/tmp/qrcode.png"
# Option 2: same thing as above, but in a 1-line script
cat "hello_world.sh" | qrencode -m 4 -o /tmp/qr.png \
&& ((eog /tmp/qr.png &); sleep 1; rm /tmp/qr.png)
Full-text QR codes like this open best in apps like the Kaspersky QR Scanner (see below).
Ensure eog doesn't blur your image when you zoom in
With eogopen, click "Image Viewer" in the top-left of your main screen --> Preferences --> uncheck "Smooth images when zoomed out" and "Smooth images when zoomed in":
Now, you'll get nice, crisp edges for scanning the QR code with your phone. Make the "Image Viewer" full-screen, then zoom in, then easily scan it from your computer screen with your phone.
QR code reader app
For opening QR Codes, I recommend the Kaspersky QR Scanner for Android or iPhone. It has a couple features I really like:
- It checks links for bad content before opening links.
- If your QR code contains the contents of an entire file, it displays it nicely as a properly-formatted text file, according to the exact text in the QR code.
But, here's a HUGE con:
- It seems to be limited to QR codes which contain < 1000 chars of text or so, so I'm looking for something better.
References
See also:
- Where I first learned about
qrencode: https://www.linux-magazine.com/Online/Features/Generating-QR-Codes-in-Linux - Software Recommendations: Secure QR code reader app for Android which can read very large QR codes (thousands of chars, ideally up to the max limit of 8000 chars or so)
- [my answer] Ask Ubuntu: Create QR code in Ubuntu 16.04
Keywords: qr code generator in Linux
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |




