Digikam

From HerzbubeWiki
Jump to: navigation, search

This page is about digikam, a software application to manage and organize digital images.


References


Configuration

Here's how I like to configure digikam. Only things that deviate from the defaults are mentioned.

Metadata:

  • Metadata > Behavior
    • Write this information to the metadata
      • Image tags
      • Captions and title
      • Rating
    • Update file timestamps when files are modified = false
  • Metadata > Views
    • Select these fields to display comments. These fields correspond to the tags that are listed by default under "Metadata > Advanced" from which to read / to which to write comments.
      • EXIF viewer
        • Image Information > ImageDescription (corresponds to tag "Exif.Image.ImageDescription").
      • IPTC viewer
        • IIM Application 2 > Caption (corresponds to tag "Iptc.Application2.Caption").
      • XMP viewer
        • Dublin Core > description (corresponds to tag "Xmp.dc.description")
        • Exif-specific Properties > UserComment (corresponds to tag "Xmp.exif.UserComment")
        • TIFF Properties > ImageDescription (corresponds to tag "Xmp.tiff.ImageDescription")
        • Darwin Core > fieldNotes (no corresponding tag)
        • PLUS License Data Format Schema > LicenseeImageNotes (no corresponding tag)
        • PLUS License Data Format Schema > LicensorNotes (no corresponding tag).
      • For these tags I could not find a metadata field: "Xmp.acdsee.notes", "JPEG/TIFF Comments".
      • After sync'ing the digikam database to image metadata, exiv2 reports that the following metadata fields contain the comment: Exif.Image.ImageDescription, Iptc.Application2.Caption, Xmp.tiff.ImageDescription, Xmp.acdsee.notes, Xmp.dc.description, Xmp.exif.UserComment, the JPEG comment.
    • Select these fields to display the rating. These fields correspond to the tags that are listed by default under "Metadata > Advanced" from which to read / to which to write the rating.
      • EXIF viewer
        • Image Information > Rating (no corresponding tag)
        • Image Information > RatingPercent (no corresponding tag)
      • IPTC viewer
        • IIM Application 2 > Urgency (corresponds to tag "Iptc.Application2.Urgency").
      • XMP viewer
        • Microsoft Photo > Rating (corresponds to tag "Xmp.MicrosoftPhoto.Rating")
        • Basic Schema > Rating (corresponds to tag "Xmp.xmp.Rating").
      • For these tags I could not find a metadata field: "Exif.Image.0x4746", "Exif.Image.0x4749", "Xmp.acdsee.rating".
      • After sync'ing the digikam database to image metadata, exiv2 reports that the following metadata fields contain the rating: Exif.Image.Rating, Xmp.xmp.Rating, Xmp.acdsee.rating, Exif.Image.RatingPercent, Xmp.MicrosoftPhoto.Rating. The latter two fields contain percent values, so a rating of 5 is written as value 99.
    • Select these fields to display keywords. These fields correspond to the tags that are listed by default under "Metadata > Advanced" from which to read / to which to write keywords.
      • EXIF viewer
        • Image Information > XPKeywords (corresponds to tag "Exif.Image.XPKeywords")
      • IPTC viewer
        • IIM Application 2 > Keywords (corresponds to tag "Iptc.Application2.Keywords").
      • XMP viewer
        • digikam schema > TagsList (corresponds to tag "Xmp.digikam.TagsList")
        • Microsoft Photo > LastKeywordXMP (corresponds to tag "Xmp.MicrosoftPhoto.LastKeywordXMP")
        • Microsoft Photo > LastKeywordIPTC (no corresponding tag)
        • Adobe PDF > Keywords (no corresponding tag)
        • Dublin Core > subject (corresponds to tag "Xmp.dc.subject").
      • For these tags I could not find a metadata field: "Xmp.lr.hierarchicalSubject", "Xmp.mediapro.CatalogSets", "Xmp.acdsee.categories".
      • After sync'ing the digikam database to image metadata, exiv2 reports that the following metadata fields contain keywords: Iptc.Application2.Keywords, Xmp.acdsee.categories, Xmp.digiKam.TagsList, Xmp.MicrosoftPhoto.LastKeywordXMP, Xmp.lr.hierarchicalSubject, Xmp.mediapro.CatalogSets, Xmp.dc.subject. Multiple keywords are written with a comma character as separator, e.g. "Foo, Bar".
    • Select these fields to display the title. These are not listed under "Metadata > Advanced" because for the title there are no advanced settings.
      • EXIF viewer
        • Image Information > XPTitle
      • IPTC viewer
        • None
      • XMP viewer
        • Dublin Core > title (digikam writes the title to the <dc:title> AOTitle
      • digikam writes the title also to the following XML attributes in the .xmp sidecar file, but for those I could not find a metadata field: acdsee:caption Versioning
    • Save files as = PNG (default JPG)


digikam databases

Summary

digikam writes its data into a few databases. By default these are SQLite files which can be accessed with any SQLite-capable database tool.

I'm using the application "DB Browser for SQLite". The application is available for all platforms. The website to download the application is sqlitebrowser.org. Apparently the application can also be obtained via Homebrew, with this command:

brew cask install db-browser-for-sqlite

Important: Do not access the SQLite database files while digikam is still running.


digikam4.db

This is the main digikam database. Everything that is not in the other databases is in here.

Kudos to the digikam developers - the database schema is quite self-explanatory!


thumbnails-digikam.db

Apparently this contains thumbnails data. I haven't played around with this yet.


recognition.db

Apparently this contains face recognition data. I haven't played around with this yet.


Recipes

Organize albums differently than in the filesystem

This is not possible. digikam lets you browse your images in various modes, but it strictly treats filesystem folders as albums, no exception.


How to edit an image's rating, title, caption and tags?

Rating:

  • Browse by album, then select the image. A 5-star rating widget appears below the image which you set to the desired value.
  • You can also set the rating in the right-hand-side panel that appears when you select the "Captions" tab at the application window's right edge.
  • Yet another alternative that I have found to set the rating is in the image editor (Tools > Image Editor), where you also must select the "Captions" tab at the editor window's right edge.


Title, caption and tags (= iPhoto keywords):

  • These do not have their own widget as "Rating" does, but otherwise you can edit them in the same places, i.e. in the right-hand-side panel that appears when you select the "Captions" tab at the application window's right edge.
  • In the version of digikam that I tested (5.9.0), the image editor seems to have a bug because the editor's "Captions" panel does not show the image's current title or caption. It does show rating and tags, though.


Find all images that have a title and/or a comment

It appears that this is not possible - at the time of writing digikam does not have search criteria that allow this kind of filtering. I also tried the usual wildcard "*", but no luck.


Show image in system's file browser

On macOS, this function is typically named "Show in Finder" in various applications. I haven't found such a function in digikam, though.

The best I could find was the menu entry Album > Open in File Manager. On macOS this opens a Finder window with the album selected. From there you have to navigate to the desired image file yourself.


Synchronize database and image metadata

The menu entry Tools > Maintenance pops up a dialog which at the bottom contains the maintenance tool named "Sync Metadata and Database". When you select this tool you can decide in which direction you want to sync: Database > Image metadata, or vice versa.

Which kind of data is synchronized depends on your digikam preferences.


Set an album's thumbnail

The album thumbnail can only be set when browsing albums (menu entry Browse > Albums).

Select the desired image, then select "Set as Album thumbnail" from the context menu.


Import versions of the same image

When you edit an image, digikam creates a new version of the image but leaves the original file intact. The new version of the image has the same file name as the original image, with the suffix

_v1

added. When I was researching the iPhoto-to-digikam migration I wondered whether it would be possible to retain the original image file from iPhoto, so I experimented a bit with the import function.

It turns out that digikam's import routine does not pay any attention to file names and does not link two files with a version history if one of them has the _v1 suffix.


Import metadata via .xmp sidecar

For the iPhoto-to-digikam migration I experimented with digikam's import routine to see what I had to put into an .xmp sidecar file so that digikam would import the various pieces of metadata that I was interested in. Here's a minimal .xmp template file that shows where to put what.

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about=""
    xmlns:mwg-rs="http://www.metadataworkinggroup.com/schemas/regions/"
    xmlns:stDim="http://ns.adobe.com/xap/1.0/sType/Dimensions#"
    xmlns:apple-fi="http://ns.apple.com/faceinfo/1.0/"
    xmlns:stArea="http://ns.adobe.com/xmp/sType/Area#"
    xmlns:xmp="http://ns.adobe.com/xap/1.0/"
    xmlns:acdsee="http://ns.acdsee.com/iptc/1.0/"
    xmlns:digiKam="http://www.digikam.org/ns/1.0/"
    xmlns:tiff="http://ns.adobe.com/tiff/1.0/"
    xmlns:MicrosoftPhoto="http://ns.microsoft.com/photo/1.0/"
    xmlns:lr="http://ns.adobe.com/lightroom/1.0/"
    xmlns:mediapro="http://ns.iview-multimedia.com/mediapro/1.0/"
    xmlns:exif="http://ns.adobe.com/exif/1.0/"
    xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmp:CreatorTool="digiKam-5.9.0"
   xmp:Rating="4">
   <dc:title>
    <rdf:Alt>
     <rdf:li xml:lang="x-default">this is a title</rdf:li>
    </rdf:Alt>
   </dc:title>
   <dc:subject>
    <rdf:Bag>
     <rdf:li>Keyword 1</rdf:li>
     <rdf:li>Keyword 2</rdf:li>
     <rdf:li>Keyword 3</rdf:li>
    </rdf:Bag>
   </dc:subject>
   <dc:description>
    <rdf:Alt>
     <rdf:li xml:lang="x-default">this is a caption</rdf:li>
    </rdf:Alt>
   </dc:description>
  </rdf:Description>
 </rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>

Some notes:

  • Note the Rating attribute which can be easily overlooked. You can put values ranging from 1-5 into the attribute because that's what digikam supports. I have not tested what happens if you use other values.
  • If digikam encounters a keyword for which it has no tag, it creates the tag. If a tag already exists, it uses that.
  • If the image contains a JPEG comment and you put a caption into the .xmp file, digikam imports both.
  • IPTC text tags only support the printable ASCII character set. The .xmp file is an XML file, though, so you can put anything you like into it and digikam will happily process it. I'm not sure what happens later when you sync the digikam database to image files' metadat.


Show only the current version of an image

In iPhoto you can manipulate an image as many times as you want - iPhoto will only store the most recent version of the image. It retains the original image, though, so you end up with two copies of the same image on disk. iPhoto always shows you the modified version of the image. To work with the original you have to discard the modified image and revert to the original.

As a casual user I always found this process a well-balanced compromise between simplicity in use and keeping my original image secure. Alas, digikam works completely different in this respect. Although it keeps the original image as well (non-destructive editing), its versioning process requires much more work from the user to achieve a similar result as in iPhoto.


Here's an overview of how versioning works:

  • When you manipulate an image in digikam, then close the image editor, digikam asks whether you want to overwrite the original image or create a new version of the image.
  • If you select "new version", digikam creates a new image file with the changed content and gives the file a suffix _v1, then _v2, and so on.
  • By the default the new file is stored in the same album as the original, and is shown as a separate image. So if you want to slideshow through the album after the edit, you now see the same image twice.
  • It's possible to save the new version of the image in a different location by clicking the drop down arrow of the "Save as new version" toolbar button, then selecting "Save new version as". But when compared with the iPhoto workflow, this is exactly the wrong thing to do: I don't want to save the modified image to a new location, I want to move the original out of the way!
  • So that's what I have to do: Manually move the original out of the way after the edit. This is not use friendly, and I also have to invent an organization scheme how/where to store my originals.


digikam has a feature where you can group several images together (select the images, then from the context menu select Group selected here). Initially I thought that this might be useful to create a group from all the versions of an image so that they can be treated as a single image. So far, however, the feature seems to be useless for my purposes due to the way how groups behave:

  • If you create another new version of the image, the new image file is not part of the group. I have to manually add the image to the group, so more work.
  • digikam does not show the newest image in the group to represent the group, it shows the oldest.

A few additional notes in case I later want to continue investigate grouping:

  • To delete an intermediate image version you first have to open the group
  • A deleted image version can be restored from the Trash, and digikam actually places the restored image back into the group where it came from. That was a surprise for me, well done digikam!


Migrate iPhoto to digikam

Summary

The migration consisted of the following steps:

  • Export data from iPhoto via AppleScript to an intermediate staging folder. The following data is exported:
    • Event names
    • The original image file, if available
    • The modified image file, if available
    • Title, comment, rating and keywords metadata
  • Prepare the exported data for importing into digikam, with the help of a shell script. This step consists of the following:
    • Retain only one image file: If a modified file is available, take this. If no modified file is available, take the original.
    • Add a file extension if none is present. An image file's extension may be missing but the image would still be usable by iPhoto because of the file's CREATOR/TYPE metadata that is present in the HFS filesystem.
    • Generate an .xmp sidecar file that contains the exported metadata
  • Configure digikam so that it reads the .xmp sidecar file when a file is imported
  • Import everything into digikam
  • Perform post-processing. This step consists of the following:
    • Delete useless comments
    • Fix encoding issues in titles and comments
    • Organize albums by date (this is necessary because digikam's album organization is coupled to the filesystem's organization of album folders)
    • Set album thumbnails (this data was lost during the iPhoto export)
    • File name cleanup (renumber image files and normalize case of file extensions)
    • Filesystem cleanup (remove .xmp sidecar files, digikam unnecessarily imported these together with the image files)
    • Sync the digikam database to image files' metadata
  • Finally: Backup the digikam photo library


Export from iPhoto

The AppleScript that I used to export data from iPhoto can be found in my tools Git repository.

If you are interested in it, please be aware that it has its clear limitations. Carefully read the blurb at the beginning of the file.


Prepare the exported data for importing into digikam

The shell script that I used to prepare the exported data for importing into digikam can be found in my tools Git repository.

Obviously this script is tailored towards processing the input from the previous step. Again, if you are interested you should carefully read the blurb at the beginning of the file.


Configure digikam

You must configure dikikam to read metadata from .xmp sidecar files. In the preferences, go to "Metadata > Sidecars" and select "Read from sidecar files".


Import into digikam

Select the menu entry "Import > Add folders", then navigate to the previously prepared import folder. Start the import.


Delete useless comments

A large number of image files contain useless technical JPEG comments which needlessly clutter the digikam database. The following SQL query reveals those comments which occur most often:

select
    comment,
    length(comment),
    count(comment) as numberOfItems
from
    ImageComments
group by
    comment
order by
    numberOfItems desc

After the migration, these were the top offenders:

  • AppleMark (3594 images)
  • KONICA MINOLTA DIGITAL CAMERA (2281 images)
  • Empty spaces (1552 images)
  • LEAD Technologies Inc. V1.01 (415 images)
  • OLYMPUS DIGITAL CAMERA (57 images)
  • Created with GIMP on a Mac (34 images)


Cleaning out these useless comments is a two-step process:

  1. Deleted any comments you no longer want from the ImageComments table with a query like this: delete from ImageComments where comment = '<the comment to delete>'.
  2. After you've deleted all comments from the database, sync the digikam database content to the image metadata. This step also removes the unnecessary comments from the image files.


Fix encoding issues in titles and comments

The import from iPhoto did not handle well special non-ASCII characters, such as German umlaut characters (äöü) - apparently iPhoto uses a different encoding than digikam for such characters. To find the problematic titles and comments I did the following.

First I copy&pasted the output of this SQL query to a text file:

select
    id, comment
from
    ImageComments
group by
    comment

I then ran an AWK one-liner script over the text file to find any titles and comments which contain something else than just ASCII characters. The script's input is expected to be a text file with two fields separated by a tab character, each field beginning and ending with a double quote character. Example:

"12345"<tab>"comment"

And here's the script. Note that the list of ASCII characters in the script is incomplete, which means that the script will result in a few false positives, i.e. it will find some titles and comments although they contain only ASCII characters. A notable example is the single quote character (').

awk 'BEGIN { FS="\t" } { comment=$2; gsub(/^"/, "", comment); gsub(/"$/, "", comment); gsub(/[a-zA-Z0-9 ,():\.\"\-\+\!\?\/]/, "", comment); if (length(comment) > 0){ print $0}}' /path/to/digikam-titles-and-comments.txt

I my case this resulted in something over 300 entries which I then had to manually fix in digikam.


Just for my personal interest's sake, here's a list of characters that I encountered:

  • German umlaut characters: äöü, ÄÖÜ
  • French and Spanish accent characters: é (e.g. Café, Puente de las Américas), à (e.g. à la), è (e.g. Saint-Saturnin-lès-Apt), ú (e.g. Gatún)
  • Scandinavian characters: ø (e.g. Tromsø), æ (e.g. Svolvær), å (e.g. Umeå), Å (e.g. Å i Lofoten)
  • Vietnamese characters: ầ (e.g. Tuần Châu), ồ (e.g. Hồ Tây), ấ and ố (e.g. Trấn Quốc), â (all previous examples), ă (e.g. Chu Văn An), ý and ổ (e.g. Lý Thái Tổ), á and ù (e.g. Tháp Rùa), ê (e.g. Chùa Kim Liên), ạ (e.g. Phố Lê Thạch)
  • Other: ° (degree sign)