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
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Endless OS 6 has Arrived
After more than a year since the last update, the latest release of Endless OS is now available for general usage.
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.