Sat, 09 Oct 2010

Updating the copyright on gallery2

Keywords: copyright gallery2 carbon

I use the Carbon theme on gallery2. The copyright in the footer can be updated via the theme configuration on the web.

[/software/gallery] permanent link

Sun, 23 Nov 2008

Adding Pictures to Gallery

I use Gallery to display my photos. I'm mostly happy with it and have developed the following work-flow to help me add pictures with the minimum of fuss.

  • Copy the pictures onto my server. I generally do this via scp or an NFS mount.
$ cp -a /media/CAMERA/DCIM /mnt/server/pics/new
  • Run my autorotate program to name the files based the date and time the pictures were taken, split them into directories based on the date, and rotate the pictures based on the EXIF orientation information.
$ autorotate /pics/new/**/*(.)   # this is zsh syntax
  • Then I run nautilus on the created directories (in /pics/new) to look at the pictures and delete the ones I don't want. Using the icon view and setting the icon size to 400% makes it quite usable for this. I can also run my rot script here to rotate any photos that were incorrectly rotated or which came from a camera without orientation information. Finally, I make sure all the photos are in the folders I want them to be in.
  • Then I log into gallery and go into my pending directory. Here I upload the directories using Add Items / From Local Server.
  • Then I can move the directories to where I want them to live and choose the highlight pictures. Nautilus is also good for this.
  • I like the majority of my albums to be arranged chronologically, and for the album to have the date and time of the first photo in it. To easily do this I then run my set_gallery_album_dates program.
$ set_gallery_album_dates
  • When I am happy, I check the albums and then set the permissions so that they are viewable. Since this is a right pain I will generally go to the top level album and remove the permissions then add them again making sure the apply changes to sub-items box is ticked. I check this has worked by temporarily setting the display mode (in the bottom right hand corner) to guest.
  • Finally, I clean up the old files. I've spent too much time double checking old directories full of pictures against what's in the gallery.
$ rm -r /pics/new/* /pics/sorted/*
  • And the very last step, unmount the memory card, put it back in the camera and format it.

[/software/gallery] permanent link

Sat, 22 Nov 2008

Adjusting EXIF dates

Sometimes EXIF date information on pictures can be incorrect, usually because the clock on the camera is set incorrectly. To adjust a set of pictures with incorrect EXIF date information I run a command similar to:

$ exiftime -v+1y -fw *

This will add one year to all the EXIF date tags in all the pictures in the current directory. The modifiers are y, m, w, d, H, M, and S and they can be adjusted forwards with + or backwards with -.

For complete details, see the man page.

[/software/gallery] permanent link

Fri, 21 Nov 2008


To watermark a picture I run a command similar to:

$ composite -gravity Center -quality 90 -dissolve 50 watermark.png pic.jpg pic-w.jpg

[/software/gallery] permanent link

Tue, 03 Oct 2006

Uploading Photos

I still use Gallery to display my photos and have recently upgraded to version 2. The upgrade was generally smooth and I'm fairly happy with Gallery2. But for a while I've been unhappy with the software I use to take the photos from my camera and organise them prior to uploading them to gallery.

My requirements are fairly simple. I want to be able to take a bunch of photographs from somewhere, organise them into directories named after the date on which they were taken, and the photographs themselves to be named after the date and time they were taken. I also want the photographs to be automatically rotated as required, losslessly. Finally, I don't want any duplicates. In this form, I can easily upload the directories to gallery.

I was sure I would be able to find something to do that, but I couldn't. So I finally got fed up and wrote something myself. It's only a hundred lines or so, so I probably should have done it myself a long time ago.

Anyway, here it is. I'll use it for a while, iron out the kinks, and then, if it seems worthwhile, I'll package it up somehow.

Note that the error checking is minimal, so don't delete your originals until you are happy with the results. Oh, and you'll need certain programs to be installed. So it will probably only work on *nix. I have somewhat unimaginatively named the program autorotate.


use strict;
use warnings;

my $Rotated = <~/g/pics/sorted>;

mkdir $Rotated or die "Can't create $Rotated: $!"
    unless -d $Rotated;

my %Rot =
    2 => "-flip horizontal",
    3 => "-rotate 180",
    4 => "-flip vertical",
    5 => "-transpose",
    6 => "-rotate 90",
    7 => "-transverse",
    8 => "-rotate 270",

sub date_name
    my ($year, $month, $day, $hour, $min, $sec) = @_;
    my $datef = "%04d-%02d-%02d";
    my $namef = "%s %02d:%02d:%02d.jpg";

    my $date = sprintf $datef, $year, $month, $day;
    my $name = sprintf $namef, $date, $hour, $min, $sec;

    ($date, $name)

for my $pic (@ARGV)
    unless ($pic =~ /\.jpe?g$/i)
        print "ignoring $pic\n";

    my $exif = `exiftags -a '$pic'`;
    my ($date, $name, $tmp);

    for my $type (qw( Created Generated Digitized mtime ))
        next if $date;
        if ($type eq "mtime")
            my $mtime = (stat $pic)[9];
            my ($sec, $min, $hour, $day, $month, $year) = localtime $mtime;
            ($date, $name) =
                date_name $year + 1900, $month +1, $day, $hour, $min, $sec;
            next unless
             $exif =~ /Image $type: (\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)/;
            ($date, $name) = date_name $1, $2, $3, $4, $5, $6;
        $date = "" if $name eq "2005-01-01 00:00:00.jpg" ||
                      $name eq "0000-00-00 00:00:00.jpg";

    my $newdir = "$Rotated/$date";
    mkdir $newdir or die "Can't create $newdir: $!"
        unless -d $newdir;

    my $rot = `jpegexiforient -n '$pic'`;
    my $trans = $Rot{$rot} || "";
    print(($trans ? "rotating" : " copying"), " $pic to $name",
          ($trans ? " [$trans]" : ""), " ");

    $tmp  = "$newdir/tmp_$name";
    $name = "$newdir/$name";

    if ($trans)
        my $command = "jpegtran -copy all $trans '$pic' > '$tmp'";
        system $command and die "Can't run: $command: $?";
        $command = "jpegexiforient -1 '$tmp' > /dev/null";
        system $command and die "Can't run: $command: $?";
        my $command = "cp -a '$pic' '$tmp'";
        system $command and die "Can't run: $command: $?";

    while (-e $name)
        system "cmp -s '$tmp' '$name'";
        if (!$?)
            print "- exists!\n";
            unlink $tmp;
            next FILE;
        no warnings "uninitialized";
        $name =~ s/(-\d+)?\.jpg$/$1 - 1 . ".jpg"/e;
        print "- trying version ", -($1 -1), " ";

    # print "- renaming => $name" if $name =~ /-\d+\.jpg$/;
    print "\n";
    rename $tmp => $name or die "Can't rename $tmp => $name: $!";
    chmod 0644, $name;

[/software/gallery] permanent link

Sun, 05 Mar 2006

Configuring Gallery

I use Gallery to display my photos. I am still running version 1. I generally work by using an old version of to upload image directories to gallery into a top level Pending folder that no one else can see. There I work on the albums before moving them to other places where they are more generally available.

A little while ago the "Move Album" page stopped working. The dropdown selection was not fully populated with all the albums, and the "Move Album" and "Cancel" buttons were missing.

I eventually got around to investigating what was happening. It turns out PHP was running out of memory. There were messages such as

Allowed memory size of 8388608 bytes exhausted (tried to allocate 177 bytes)

in the apache error.log file.

I fixed the problem by adding the following line to the .htaccess file for Gallery, which on Debian is found at /etc/gallery/htaccess

php_value memory_limit 4500000000

which bumps the memory up from about 8MB to about 4.5GB. Overkill? Maybe. But I have enough swap space, and that should hopefully allow me to create zip files for the albums (which gallery does for you) and they'll be of a suitable size to burn to dvd.

The other thing I always do after Debian upgrades Gallery for me is edit config.php (found at /usr/share/gallery/config.php in Debian) and change PhotoAlbumURL and AlbumDirURL to be relative URLs. Otherwise, for some reason I don't fully understand, Gallery runs extremely slowly for me this side of my firewall.

(Note that I have had to write PhotoAlbumURL and AlbumDirURL even though the actual variable names start with a lower case letter in each case. This seems to be some problem related to kwiki. Simply adding an exclamation mark in front of each variable does not help, even though it is needed for the way I have written the variable names. Does anyone know the solution to this problem? Note that the answer is probably not "don't use kwiki" unless it is accompanied by information on what to use instead.)

Why the Gallery developers don't get rid of the check that those URLs cannot be relative is beyond me. I presume they are saving users from themselves, but I dislike software that thinks it knows better than me.

[/software/gallery] permanent link

November 2022
Sun Mon Tue Wed Thu Fri Sat