Photo diary
DIY Photo Sharing

Instead of relying on a third-party service for instant photo sharing, you can build your own solution using existing software and a pinch of PHP and Python scripting.
Google+, Instagram, EyeEm – services for instant photo sharing – are plentiful. However, the broad choice of photo sharing services doesn't mean you can't build your own photo-sharing solution. In fact, if you are not fond of the idea that third-party services harvest and datamine your accounts, as well as use your photos for their own purposes, then going the DIY route makes a lot of sense.
Privacy concerns, however, are just one reason for deploying a home-brewed solution. By building your own instant photo-sharing application, you can focus on the features that are important to you, leaving out all the unnecessary embellishments. Creating your own app is also an excellent opportunity to master some basic scripting skills and write code that you can later reuse in other projects.
Building your own instant photo-sharing system doesn't have to be as daunting as it may sound, provided you are interested in creating a utilitarian solution rather than an Instagram killer. In this article, I'll guide you through the process of building a no-frills instant photo-sharing system that uses existing software and requires only a minimum of scripting. Creating and setting up the entire solution shouldn't take more than a couple of hours, which makes it a perfect project for a rainy weekend.
Preparatory Work
Before you get down to the nitty-gritty, you have to do some preparatory work. Because the Photocrumbs app relies on existing software, you must install several key components on your Android device and a Linux server. On the Android device, you have to install two pieces of software: Scripting Layer for Android (SL4A) and Python for Android [1]. These two components add Python scripting capabilities to Android (Figure 1).
For the Linux server, you have to install the Apache HTTP server, PHP, and the ProFTPD FTP server. To do this on Debian-based Linux distributions, run
apt-get install apache2 php5 proftpd
as root. Next, grab Photocrumbs' source code from the project's GitHub repository [2]. If you have Git installed on your system, you can do that by cloning the repository with
git clone git@github.com:dmpop/photocrumbs.git
Open the photocrumbs.py
Python script in a text editor and specify the correct server
, username
, and password
values. Save the changes and move the script to the sl4a/scripts
directory on your Android device. Then, move the entire photocrumbs
directory to the root of your server and make the photocrumbs/photos
directory writable with the chmod 774 -R photos
command.
Next, you need to tweak the ProFTPD configuration. On the server, open the /etc/proftpd/proftpd.conf
configuration file in a text editor, locate the DefaultRoot
parameter, and modify it as follows:
DefaultRoot /var/www/photocrumbs/photos
(Note that the exact path depends on the actual root directory of your server and the default directory for storing photos.) Then, restart the ProFTPD server by running the
/etc/init.d/proftpd restart
command as root. Changing the DefaultRoot
parameter ensures that any FTP connection is automatically routed to the specified directory.
Finally, you have to make the server accessible from the Internet, so you can establish an FTP connection. To do this, you need to configure port forwarding on your router. Consult the documentation supplied with the router to find out the exact port forwarding procedure.
How Photocrumbs Works
The core of the Photocrumbs server application is a relatively simple PHP script (Listing 1), which pulls files with the .jpg
file extension from a specified directory and displays them as a single-page stream. The script performs several other operations, too. It reads the values of the $title
, $tagline
, and $footer
variables from the config.php
file and inserts them into the page.
Listing 1
The index.php Script
The exif_read_data()
routine reads EXIF data from each photo (aperture, shutter speed, ISO, and date); other statements take care of parsing the obtained values and displaying them on the page. By default, the script pulls photos from a directory specified in the config.php
file. However, it can also display photos from a specific subfolder inside the default directory by reading the $f
variable from the entered URL.
Another key part of the Photocrumbs system is the photocrumbs.py
Python script on the Android device. The basic version of the script (Listing 2) performs three operations: It captures a photo, prompts the user to enter a short note, and then uploads both parts to the server via FTP. The script also saves the captured photo and the accompanying note in the photocrumbs
directory on the Android device (if the directory doesn't exist, the script creates it).
Listing 2
Photocrumbs.py Python Script
Using and Tweaking Photocrumbs
Thanks to its simple design, Photocrumbs is very simple to use. All you have to do is run the photocrumbs.py
script on your Android device, snap a photo, enter a note, and upload both to the server. To launch a script on Android, you need to open the SL4A app first and select the item you want from the list of available scripts. Although that additional step is not particularly complicated, it can quickly become a nuisance.
Fortunately, the SL4A app lets you add a homescreen widget for launching the script with a single tap (Figure 2). To add the widget, long-click on the SL4A Scripts item in the Widgets section (how you access it depends on your specific Android device) and drag the item onto the homescreen. Then, select the photocrumbs.py
script, and you are done.
By default, the PHP script running on the server obtains the path to the directory containing photos from the config.php
file. However, you can point the script to a specific subfolder inside the default directory using the $f
variable in the URL. For example, if you want to view photos stored in the photos/tokyo
subdirectory, the URL should be as follows (replace <127.0.0.1>
with the actual IP address or domain name of your server):
http://<127.0.0.1>/photocrumbs./index.php?f=tokyo
This simple feature can be useful for keeping your photocrumbs neatly organized into folders (Figure 3).
The Python script in Listing 2 pushes snapshots and notes to the FTP server without a prompt. This setup can be problematic when either the Android device doesn't have a fast and reliable connection or data transfer is too expensive (or when you prefer to edit photos before uploading them). To fix this, you might want to tweak the script to ask whether or not it should upload the captured snap and the accompanying note. This change can be made using a couple of Android-specific Python routines and the if...else
condition. Look at the photocrumbs.py
script in the Photocrumbs repository to see how this functionality has been implemented. Alternatively, you can create two versions of the script in Listing 2: one with FTP upload and the other without. This way, you can run the appropriate script depending on the situation.
In the original version of photocrumbs.py
, the FTP connection variables are hard-wired into the script. However, you can also store the connection info in a separate configuration file and point the script to it. To do so, create a config.ini
file, which should look something like this,
[ftp] server = 127.0.0.1 username = foo password = pass
then add the following code to the photocrumbs.py
script
from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('config.ini')
and modify the FTP connection variables as follows:
server = parser.get('ftp', 'server') username = parser.get('ftp', 'username') password = parser.get('ftp', 'password')
Because Photocrumbs' PHP script can display photos stored in a subdirectory by reading the $f
variable in the URL, you can also add the subdir =subdirname/
configuration option (note the trailing slash) to the config.ini
file and modify the conn.storbinary
statement in the photocrumbs.py
script as follows:
conn.storbinary('STOR ' + subdir + timestamp + '.jpg', file) conn.storbinary('STOR ' + subdir + note, file)
In this way, you can point the script to a specific directory on the fly. Make sure, though, that the specified subdirectory exists on the server. Also, make sure the config.ini
file is saved in the sl4a
directory and not in sl4a/scripts
. If you choose not to upload snaps and notes using the script, then you will need to do that later. Plenty of third-party apps can be used for that purpose, including the excellent FolderSync [3].
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
Kubuntu Focus Announces XE Gen 2 Linux Laptop
Another Kubuntu-based laptop has arrived to be your next ultra-portable powerhouse with a Linux heart.
-
MNT Seeks Financial Backing for New Seven-Inch Linux Laptop
MNT Pocket Reform is a tiny laptop that is modular, upgradable, recyclable, reusable, and ships with Debian Linux.
-
Ubuntu Flatpak Remix Adds Flatpak Support Preinstalled
If you're looking for a version of Ubuntu that includes Flatpak support out of the box, there's one clear option.
-
Gnome 44 Release Candidate Now Available
The Gnome 44 release candidate has officially arrived and adds a few changes into the mix.
-
Flathub Vying to Become the Standard Linux App Store
If the Flathub team has any say in the matter, their product will become the default tool for installing Linux apps in 2023.
-
Debian 12 to Ship with KDE Plasma 5.27
The Debian development team has shifted to the latest version of KDE for their testing branch.
-
Planet Computers Launches ARM-based Linux Desktop PCs
The firm that originally released a line of mobile keyboards has taken a different direction and has developed a new line of out-of-the-box mini Linux desktop computers.
-
Ubuntu No Longer Shipping with Flatpak
In a move that probably won’t come as a shock to many, Ubuntu and all of its official spins will no longer ship with Flatpak installed.
-
openSUSE Leap 15.5 Beta Now Available
The final version of the Leap 15 series of openSUSE is available for beta testing and offers only new software versions.
-
Linux Kernel 6.2 Released with New Hardware Support
Find out what's new in the most recent release from Linus Torvalds and the Linux kernel team.