Taking a screenshot on a Raspberry Pi from a remote location

Taking a screenshot on a Raspberry Pi from a remote location
Published: by Renier Delport
Collection(s): Raspberry Pi

Whether it is for debugging purposes, making images for tutorials or capturing a moment in a game, screenshots (screengrabs or screen captures) often come in handy. Most operating systems, including Raspbian, will have options to create screenshots by using the keyboard, but what if no keyboard is connected?

This is an ongoing post. Please suggest corrections, explanations, etc. in the comment section at the bottom of this page.

A screenshot is a digital image of what is visible on the screen at that specific point in time. It includes everything that is displayed. Often the Raspberry Pi is used as a standalone device without any peripherals connected to it, which makes using the keyboard impractical. A popular solution in this case is to make use of a remote system to trigger the screenshot command.

To be able to take screenshots from a remote location the Raspberry Pi needs to be connected to a network and the username, password and IP address is required. SSH access to the Raspberry Pi needs to be available. The process will be done using raspi2png and PuTTY from a computer connected on the same network. To install raspi2png a connection to the internet will be required.

raspi2png

raspi2png is an utility with the purpose of taking a “snapshot” of the Raspberry Pi screen. It is also reported to work well for Minecraft screen captures. For more information see Andrew Duncan’s raspi2png Github page.

After the raspi2png command is triggered, a screenshot is saved as a PNG file. The screenshot command is triggered on the Raspberry Pi itself using a terminal command, but because the command can be triggered from a remote location it can capture both GUI and terminal screens.

The utility and its dependencies are to be installed locally on the Raspberry Pi. The raspi2png project files need to be downloaded from Github, after which they need to be compiled.

PuTTY SSH terminal window
PuTTY terminal window in Windows 10 connected to a Raspberry Pi.

The first step is to connect to the Raspberry Pi using  PuTTY. After having terminal access to the Raspberry Pi, do an update/upgrade first:

sudo apt-get update
sudo apt-get upgrade -y

The following commands will install the dependencies:

sudo apt-get install libpng12-dev -y
sudo apt-get install git -y

It is recommended to download the raspi2png project files to the /home/pi/raspi2png directory. The /raspi2png directory will be created automatically, but to make sure you’re in the /home/pi/ directory, use:

cd /home/pi

To download the raspi2png project files from Github, use:

git clone https://github.com/AndrewFromMelbourne/raspi2png/

To compile the project files, simply use the make command while in the /raspi2png directory:

cd /home/pi/raspi2png
make
cd

If the make process was successful, a screenshot can then be triggered by running the raspi2png command:

/home/pi/raspi2png/raspi2png

The screenshot is saved as snapshot.png. It is saved in the same directory as from where the command was triggered from. The old screenshot will be replaced each time a new command was triggered. The location where the screenshot will be saved can also be set with the -p command line option (see below)

Captured screenshots can be renamed and copied to a different location using WinSCP.

raspi2png also has some handy command line options which can be used to extend the functionality. From the Github page, the following command line options are available:

Usage: raspi2png [-p pngname] [-v] [-w ] [-h ] [-t ] [-d ]
-p - name of png file to create (default is snapshot.png)
-v - verbose
-h - image height (default is screen height)
-w - image width (default is screen width)
-t - type of image captured
     can be one of the following: RGB565 RGB888 RGBA16 RGBA32
-d - delay in seconds (default 0)

The most useful are -p , and -d. For example:

/home/pi/raspi2png/raspi2png -d 5 -p "snap_01.png"

will create an image file called snap_01.png after a delay of 5 seconds, and:

/home/pi/raspi2png/raspi2png -p "/home/pi/snap_02.png"

will create an image file called snap_02.png in the /home/pi directory (irrespective where the directory the command was triggered from).

Related product links

Please support Behind The Scenes by using these links to purchase these related products online from our partner websites. Links will open in a new window.

5V 2.5A Power Supply With On/Off Switch (US, EU)
Supplier: BangGood
Delivers: Worldwide
Price range: U$D 4.70 / ZAR 70
Description: Input 100-240V AC. 75x41x29mm. Perfect for Raspberry Pi 2/3.
Ethernet RJ45 Adapter Cover (30 pcs, black, blue, red, white, yellow, green)
Supplier: BangGood
Delivers: Worldwide
Price range: U$D 2.50 / ZAR 37
Description: Covers RJ-45 plugs used for any CAT5, CAT5E, CAT6 or CAT6a Ethernet cable.
Network Cable Kit
Supplier: BangGood
Delivers: Worldwide
Price range: U$D 48 / ZAR 720
Description: For CAT5, CAT5e and CAT6 cables. Includes network cable tester (with 9V battery), network tool crimper, punch tool, cable stripper/cutter, 30m Cat6 network cable, 30x 8P8C RJ45 modular plugs and 30 x RJ45 connector boots.
Network Cable Testing Tool (RJ45/RJ11)
Supplier: BangGood
Delivers: Worldwide
Price range: U$D 4.50 / ZAR 70
Description: RJ11 RJ45 CAT6 CAT5e network cable testing tool. Easily find wrong connections, short circuits and open circuits. 9V battery not included.
Raspberry Pi 3 Model B 1.2Ghz
Supplier: BangGood
Delivers: Worldwide
Price range: U$D 34 / ZAR 660
Description: 64-bit quad core processor running at 1.2GHz, 1GB RAM, dual-band 2.4GHz and 5GHz wireless LAN, Bluetooth 4.2/BLE, faster Ethernet and PoE capability via a separate PoE HAT.
Raspberry Pi 3 Model B+ 1.4Ghz
Supplier: BangGood
Delivers: Worldwide
Price range: U$D 57 / ZAR 850
Description: 64-bit quad core processor running at 1.4GHz, 1GB RAM, dual-band 2.4GHz and 5GHz wireless LAN, Bluetooth 4.2/BLE, faster Ethernet and PoE capability via a separate PoE HAT.

Save, share & Disqus

Use the buttons below, on the left or the bottom of this page to share this post. Your comment is important, but don't be a shit. Keep it constructive and polite.

Comment via Disqus

Disqus is a worldwide comment hosting service for web sites and online communities. This secure platform ensures a pleasant commenting environment which is manageable from one account. Use the Login button to sign up.

More Raspberry Pi related posts

Get WP Toolset – for custom WordPress development without programming
Get WP Toolset – for custom WordPress development without programming
21 September 2018
Extend the functionality of WordPress with regards to its ability to store data and publish it on your website. More…
About the author
Renier busies himself with improving his English writing, creative web design and his websites, photoshopping, micro-electronics, multiple genres of music, superhero movies and badass series.