Posts Tagged ‘batch processing’
Process Photos with digiKam’s Batch Queue Manager and a Bash Script
One of digiKam’s lesser known features is the ability to link scripts to notifications. At first sight, this may seem like a rather obscure functionality, but it can be put to some clever uses. Say, you want to keep a portfolio of selected photos on a mobile device. Resizing multiple photos to a specified size to make it easier to view them on the mobile device and transferring the processed photos from digiKam to the mobile device manually is not very practical. And this is where the ability to trigger scripts via notifications can come in handy. You can attach a simple Bash script to the Batch queue completed notification, so it’s triggered automatically when the Batch Queue Manager tool is done processing photos.
The Bash script is very simple, indeed. It uses the rsync tool to copy the processed photos from the source directory (in this case, it’s /home/user/Photos/Processed) to the /DCIM/Camera directory on the mounted SD card:
#!/bin/bash
rsync -avz --delete /home/user/Photos/Processed /media/0CFA-5602/DCIM/Camera
Paste the code above into an empty text file and save it as a postprocess.sh file (don’t forget to replace the example paths with the actual paths to the source and destination directories). Make then the script executable using the chmod o+x postprocess.sh command.
In digiKam, choose Settings » Configure Notifications and select the Batch queue completed item. Tick the Run command check box, and enter the path to the postprocess.sh script in the appropriate field. As you might have guessed, this links the script to the notification, so the script is triggered as soon as the batch operation is finished.
Next, create a tag (e.g., transfer) in digiKam and assign it to the photos you want to transfer to the mobile device. Alternatively, you can use a specific color label for that. Use then the Filter right sidebar to display the tagged or labelled photos, select them, and press Ctrl+B (or choose Tools » Batch Queue Manager) to add them to a new batch queue. In the Queue Settings section, click on the Target tab and select the Photos » Processede sub-album. Under the Base Tools tab, double-click on the Transform » Resize tool to add it to the Assigned Tools section. In the Tool Settings pane, specify the desired length. You can choose between several presets, or enable the Use Custom Length option and specify the desired length.
Hit then the Run button, and once the batch operation is completed, the assigned Bash script copies the resized photos to the mounted SD card.
You can tweak the script to perform other post-processing actions, too. For example, if you use the llgal command-line tool to generate static HTML photo galleries, you can tweak the script to add the processed photos to an HTML album. The script may look something like this:
cd /home/user/Photos/Processed
llgal --exif --li -L --sx 800 --sy 600
In other words, you can do all kinds of clever tricks by linking scripts to notifications.
Command-line Photographic Workflow on Linux
Most Linux photographers use graphical applications like digiKam, Rawstudio, or darktable as their tools of choice for processing and managing photos. But it is possible to set up a photographic workflow built around command-line tools that can handle a wide range of photographic tasks: from fetching photos from your camera and convert RAW files to the JPG format, to backing up the photos on a remote machine and even publishing them on the web. Here is a sample workflow you can use as your starting point.
The first order of business is to set up a dedicated working directory for storing photos transferred from your camera:
mkdir ~/fotki
Next, make sure that the gPhoto software is installed on your system. gPhoto is available in the software repositories of many popular LInux distributions, so you can install it using your distro’s package manager. On Ubuntu, this can be done using the sudo apt-get install gphoto2 command. Connect then the camera to your machine and run the gphoto2 –auto-detect command. If your camera is supported, the command should return brief camera info.
To transfer photos from the camera to the fotki directory, run the following commands in the terminal:
cd ~/fotki
gphoto2 --get-all-files
If your camera supports tethered shooting, you can use gphoto2 to automatically transfer photos from the camera as soon as you take them. To do this, use the gphoto2 –capture-tethered command.
Once the photos have been transferred, you might want to change their names to something more descriptive. One way to do this is to use the exiftool utility (on Ubuntu, you can install it using the sudo apt-get install libimage-exiftool-perl command). For example, the following command renames Nikon RAW files using date info from EXIF metadata:
exiftool -d %Y%m%d/%Y%m%d-%H%M%S.%%e "-FileName<DateTimeOriginal" *.NEF
If you shoot in RAW, the UFRaw utility can come in handy when you need to convert RAW files to the JPEG format. To install it on Ubuntu, run the sudo apt-get install ufraw command. Use then the ufraw-batch tool to convert RAW files:
ufraw-batch --out-type=jpeg *.NEF
The command above uses the default options for converting RAW files, and to get the best result, you might want to tweak them. For a full list of supported options, run the man ufraw-batch command. Here is an example of a more advanced ufraw-batch command:
ufraw-batch --wb=camera --rotate=camera --out-type=jpeg --out-path=jpeg/ nef/*.NEF
The good old rsync utility can take care of backing up your photos to a local destination, external storage device, or a remote server. For example, the following command backs up the fotki directory to a server on the local network using a secure SSH connection:
rsync -avhe ssh --delete ~/fotki user@remotehost:/home/user/fotki
Finally, if you want to publish your photos on the web, the llgal tool got you covered. It can generate no-frills static HTML galleries. As any command-line tool worth its salt, llgal supports a handful of options for you to tweak. The -R option, for example, can be useful if you want llgal to include subdirectories into the final gallery. To give the gallery a name, use the –title option as follows: –title “Garden Flowers.” llgal doesn’t generate thumbnails, so if the source directory contains large image files, it’s a good idea to limit their width and height to a specific size. This can be done using the –sx and --sy options. And you can use the –exif option to display EXIF metadata for each photo. To sum up, here is an example:
llgal --exif --li -L -R --title "Garden Flowers" --sx 800 --sy 600
To see a list of all available options supported by llgal, run the llgal –help command.
These are just a handful of tools you can use to set up a command-line photographic workflow on Linux. There are, of course, many other handy command-line tools out there you can incorporate into your workflow. Using, for example, the HDR script, you can automate the process of creating HDR images, while the Enfuse tool (it’s part of the Hugin software) can be used for focus stacking.
Batch Process Photos in digiKam
When you need to apply the same action to multiple photos, digiKam’s batch processing capabilities can come in rather handy. And the photo management application provides different ways to apply actions to a photo batch in one fell swoop.
For starters, you can perform certain actions on all photos in a specific album. To do this, right-click on the desired album, and choose the action you want from the Batch Process context menu. The actions available in the menu include Image Effects, Recompress Images, Resize Images, DNG Converter (lets you convert RAW files into the DNG format), and Batch RAW Converter (allows you to process the RAW files using the Batch RAW Converter tool).
For more serious batch processing, you should use the dedicated Batch Queue Manager tool. Using it, you can set up rather advanced processing profiles and manage multiple queues. To add selected photos to the Batch Queue Manager, choose either Image » Add to Current Queue (alternatively, use the Ctrl+B keyboard shortcut) or Image » Add to New Queue (or press Ctrl+Shift+B). This opens the Batch Queue Manager and adds the selected photos to an existing or new queue. To specify the actions you want to perform on the photos in the queue, pick the desired tools from the Base Tools section, and specify the settings for each tool in the Tool Settings pane. The File Renaming section in the Queue Settings pane lets you specify a renaming rule to apply to the modified photos. This can help you to differentiate between the processed photos and their originals.
Batch Convert Nikon RAW (NEF) Files to JPEG
Need to convert multiple .NEF files to the JPEG format? You can easily do this from the command line using the UFRaw tool. First off, install the UFRaw package on your system. UFRaw is available in the software repositories of many popular Linux distributions, so you can install it using your distro’s package manager. On Ubuntu, use the following command:
sudo apt-get install ufraw
Launch then the terminal, switch to the directory containing NEF files, and run the following command:
ufraw-batch --out-type=jpeg --out-path=./jpg ./*.NEF
That’s all there is to it.
Watermark Photos with digiKam
While there are many ways to protect your photos from unauthorized use, watermarking still remains the simplest and probably the most effective technique that can help you to identify you as the creator and make it difficult to use your works without permission.
Although digiKam supports watermarking, this feature is hidden so well that you might not even realize that it’s there. This is because the watermarking function in digiKam is tucked under the Batch Queue Manager tool which you can use to watermark multiple photos in one go. Here is how this works in practice. Choose Tools | Batch Queue Manager (or press the B key) to open the Batch Queue Manager tool. Drag the photos you want to watermark from a digiKam album onto the Queues pane to add them to the current queue. Click on the Base Tools tab in the Batch Tools Available pane and double-click on the Add Watermark tool to add it to the Assigned Tools pane.
digiKam can use text or images as watermarks, and you can choose the desired watermark type in the Tools Setting pane. If you want to use the Image type, make sure that you already have a graphics file handy. Specify then the available settings such as Placement, Size, and Margins. Next, select the target folder in the Target section of the Queue Settings pane. In the Behavior section, you can specify what the system should do if it detects a file with the same name as the processed one in the target folder. You can either choose to overwrite the existing file or rename the processed file before saving it. You can also use the options available in the File Renaming section to specify a renaming rule to automatically rename the processed files.
Once you are satisfied with the settings, hit the Run button, and once digiKam’s finished, you’ll find the watermarked photos in the target folder.




