How the go-photoframe.sh script works

This script 'wraps it all together' and is designed so all you have to do (after update/upgrade) is create the /photos folder, place all 3 scripts inside (making them executable) and then add this script to the end of the Pi boot-up command list (the /etc/rc.local local file)

Install ImageMagick

One of the first things the script does is check if ImageMagick 'convert' exists, and, if not, apt-get it and install it (it's about 80Mb) #!/bin/bash # go-photoframe.sh for Mk2 PhotoFrame, last updated 2016 Sept 28 # test if ImageMagick convert exists, and if not get it now hash convert # check for convert (status appears on screen) if [ $? -eq 1 ]; then # convert not found, install it now echo >&2 "convert not found, installing ImageMagick" sudo apt-get install -y imagemagick fi # To check if it installed OK, do a basic 'convert with resize' :- convert {sourcefile} -resize '1600x1200' {destfile} (where 1600 is max width, 1200 max height and the image will be resized to fit)

ram-disk

To avoid wearing out the SDHC card directory with 'linking' of files, a ram-disk is used for the fbi display files which means we only read the SDHC card directory and then read (copy) photos from SDHC card to the ram-disk (i.e. to the free buffer in tmpfs). Of course, after a reboot, we need to create the ram-disk folder (we don't care if it already exists, just let the create attempt error out) # tbd

The launch sequence

Start by launching the other 2 scripts in the background :- # Launch background tasks # get and resize (comment this out if you don't need Pi to update /photos from USB etc) sudo /photos/get-photo.sh & # select next for display sudo /photos/set-photo.sh & # Fbi will 'run for ever' (stepping from one photo to the next) to avoid the 'memory leak' problem found when it's allowed to stop (and is restarted). In order to 'switch' the photo being displayed we 'cheat' fbi by changing a symbolic link from the 'fixed' file it's showing to a new one we want to show next. It turns out that fbi actually has to be given 3 'fixed' file names because, even when fbi is told 'no cache', it will actually pre-fetch two. Only when it has to 'step' across 3 or more files will it actually go read the image data each time. To make it easy to 'switch', fbi is given 3 dummy 'alias' files, all 3 of which 'point' to a single 'intermediate' dummy 'display.jpg' = so switching just means changing the display.jpg file symbolic link. To speed up the appearance of a new photo (after a switch), we have to get fbi to step across the 3 'dummy' photos 'as fast as possible'. The fastest step rate turns out to be about 1 second (so a 3 second cycle for all 3 files). # give the go-photo (background) script a chance to copy the first image into buffer1.jpg and alias link it to display.jpg sleep 5 # now generate the 3 fbi files and alias them to the display file, which is itself an alias to one of the buffer files # (-f means overwrite any existing link of the same name) ln -s -f display.jpg alias-1.jpg ln -s -f display.jpg alias-2.jpg ln -s -f display.jpg alias-3.jpg # # launch fbi foreground task on a 3 second cycle fbi -T 1 -d /dev/fb0 -noverbose -t 3 -cachemem 0 alias-1.jpg alias-2.jpg alias-3.jpg Notes. During development, the '-a' flag (auto-rescale) was used so fbi would cope with 'any' sized photo sent to it. Needless to say, sometimes fbi got this wrong (adding 'black bands' to both top and bottom of the display at the same time), so we rely on the get-photo script to scale correctly (and don't need -a) We actually need to copy the next photo to the ram-disk (so it can't be deleted whilst it's being displayed), and that means we have to avoid over-writing the current displayed photo with the next (if we do, the actual screen display becomes 'corrupted', although it does usually recover without the Pi crashing). This means using a pair of 'buffer' files. This means display.jpg is 'linked' to one of two bufferX.jpg files. Because fbi is stepping at 1s, when we change the display.jpg link (to point at the new bufferX.jpg), the new photo should appear 'on screen' within 1 second. Swapping out the image and updating the display link is done by another script running in the background - for more details, see the 'set-photo' script. To have your photoframe start-up on each boot, add "/photos/go-photoframe.sh" at the end of /etc/rc.local