User Tools

Site Tools


Site Information

Interactive Maps



Table of Contents


You didn't think I uploaded every image individually, did you?


When editing a page and adding media, the Dokuwiki media manager uploads images to the directory ~/domain.tld/data/media/cat1/cat1.1/cat1.1.1/ where:

  • "~" = your user ID on the server
  • "domain.tld" = your domain name (e.g. bennett1) and Top Level Domain extension (e.g. .org, .com, .edu, .net etc)
  • "data/media" is the Dokuwiki standard place for media
  • "cat1/cat1.1[/…]" are the hierarchy representing your sites page and sub-page structure

The path is represented internally by Dokuwiki as :cat1:cat1.1:cat1.1.1:[:…] with each subpage separated by a colon (:). NOTE: the dots (e.g. cat1.1.1) are for your benefit - Dokuwiki doesn't allow dots in the filename except to denote the extension. Live with it!

That given, I used the following code


Wait. Before I give you the actual code, we need to talk about me being lazy and modifying GIMP so I don't have to work so hard…

In GIMP, I added two shortcut keys to quickly open the G'MIC interface, and then Export As so I didn't have to do a lot of menu mouse-clicking. You can, too, under: Edit→Keyboard Shortcuts. FYI: The default Ctrl+Shift+S for Export As/ conflicted with the Windows shortcut key I've used for years for another application, so I changed GIMP's. ===== Perl Code ===== You've been waiting, patiently. So here it is - finally! So that it would be easy to copy/paste the resultant Dokuwiki code to create pages, the Windows directories became the Dokuwiki page header name. NOTE: In the end, all the images are uploaded via FTP to the same Dokuwiki directory. Dokuwiki has restrictions. For example, names of media:

  • Must be lower case
  • May not contain special characters (e.g. dash, ampersand, etc) even if your operating system allows them (because but not all systems have to!)

So I used a loose naming convention for file names:

  • underscore becomes a space
  • the characters baw become "B & W"
  • I gave each a 2 or 3 character leading abbreviation to denote which filter category they belong. Since all the files are uploaded to the same directory in Dokuwiki, this makes future maintenance easier!

While the underscores and baw remain as part of the image name, they are replaced in the image description on the page.

This program creates a file with the Dokuwiki syntax within for each directory.

#!/usr/bin/perl -w
use strict;
my $sDirStart = q{.};
my @aDirectories;
my $sDotDot = q{..};
# domain.tld dokuwiki path
my $sDirWiki = q{:scode:gimp:gmic:};
# this gets DIRECTORIES ONLY (starts at the bottom ('right-most') expression):
@aDirectories =                     # assign map's list of directories to array
    map  { $_ }                     # if directory, add it to "map's" list (collection)
    grep { -d $_ }                  # test (-d) if file is a directory
    map  { "$_" } <${sDirStart}/*>; # get a list of all files in directory
foreach my $sDir (@aDirectories) {
  # remove the leading "./" from the filename
  $sDir =~ s#\./##;
  # I have other directories in the project, all beginning with "_" so skip them
  next if $sDir =~/^_/;
  my $sWikiTxt = qq{_$sDir.txt};
  my $sBW = q{B&W};
  eval {
      open FWIKI, '>', $sWikiTxt or
          die "Can't open $_ for read: $!\n";
          # 'or die' triggers $@
  if ($@) {
      print $@;
      print "$sWikiTxt failed to open\n";
  my $sHdr = $sDir;
  $sHdr =~ s/_/ /g;   # Replace "_" with " "
  $sHdr =~ s/(\w+)/\u\L$1/g;   # Cap 1st letter in each word of directory name
  $sHdr =~ s/ And / \& /g;   # replace " and " with "&"
  print qq{====== $sHdr ======\n\n};
  print FWIKI qq{====== $sHdr ======\n\n};
  my @aFileNmes = glob(qq{*.jpg});
  foreach my $file (@aFileNmes) {
      my $sDescript = $file;
      $sDescript =~ s/.*?_(.*).jpg/$1/;
      $sDescript =~ s/_/ /g;
      $sDescript =~ s/baw/${sBW}/g;
      $sDescript =~ s/(\w+)/\u\L$1/g;   # Cap 1st letter in each word
      # {{:scode:gimp:gmic:pat_boxfitting.jpg?400|}}\\
      # Box Fitting
      print qq/{{${sDirWiki}${file}?400|$sDescript}}\\\\\n$sDescript\n\n/;
      print FWIKI qq/{{${sDirWiki}${file}?400|$sDescript}}\\\\\n$sDescript\n\n/;
  close FWIKI;

Now all I have to do is FTP all the images to the appropriate directory while I fix lunch, and then double-click each description file, copy the Dokuwiki syntax, and create the new page on my system. Sweet!


scode/gimp/gmic/perl.txt · Last modified: 2019/07/31 07:10 by terrill