[Bins] Add images from gqview

Dragos Constantinescu d.constantinescu at tu-bs.de
Mon Feb 6 14:34:42 GMT 2006

Hash: SHA1


A new version of gqv2bins is attached.


1. Since not all distributions provide the system command "mkdirhier",
    I replaced it with a perl routine.

2. The gqview keywords are now added to the field "keywords" in the XML
    image file. This enables the search using keywords. For this to work,
    "keywords" have to be added to the "searchFields" parameter in the
    bins configuration file and the key "keywords" should be added to the
    "getFields" function in bins source.

3. Very small changes in the manual page.

All the best,


         Dragos                                PGP key ID: A0887098


Version: GnuPG v1.2.4 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

-------------- next part --------------
#!/usr/bin/perl -w
use Getopt::Long;

GetOptions ('add'    => \$add,
            'remove' => \$remove 

$file = $ARGV[0];

die "please specify --add or --remove" unless ($add or $remove);

#### cange these according to your cfg ######
$imgdir='/space/dragos/poze/'; # this is your gqview directory tree base
$targetdir_base='/space/dragos/www/src-pcs/'; # image source directory for bins
$albumdir_base='/space/dragos/www/poze/'; # final location of the album

# the key "keywords" should be added to the "getFields" function in bins source 
# in order to enable the search

$file =~/$imgdir(.+\/)(.+?)$/;
push @albumfiles, $albumfile.'.details.html';

@kw=@{$meta{'keywords'}}; $comment=$meta{'comment'};

print "$file:
       keywords: @kw
       comment:  $comment\n";

if ($add) {
  push @{$meta{'keywords'}}, 'bins';
  $targetdir=~s/ /\\ /g;$file=~s/ /\\ /g;$link_name=~s/ /\\ /g;
  system "chmod a+rx $targetdir
          ln -s $file $link_name
          /usr/local/bin/bins_edit --description \"$comment\" --generic keywords=\"@kw\" $link_name\n";
  print "image added to the album. 
  run bins $targetdir_base $albumdir_base \nto reflect the changes\n\n";

if ($remove) {
  print "removing link, xml, and album files\n";
  foreach $kwrd (@kw) {push @{$meta{'keywords'}},$kwrd unless $kwrd eq 'bins'};
  print "run bins $targetdir_base $albumdir_base \nto reflect the changes\n\n";

sub read_meta {
  my $img=$_[0];
  my ($path,$imgname)=($1,$2);
  my $metafile=$path.".metadata/".$imgname.".meta";
  my $header=''; my @keywords=(); my $comment="";
  my %meta=(header => $header, keywords => \@keywords, comment => $comment);
  return %meta unless -r $metafile;

  my $field='';
  while (<MFILE>){
    chomp(my $line=$_);
    next if $line eq '';
    if ($line=~/^\[(.+)\]$/){
    next if $field eq '';
    last if $line =~/#end/;
    if ($field eq "keywords") {
      push @keywords,$line; 
    } elsif ($field eq "comment") {
  close MFILE;
  return %meta;

sub write_meta {
  my ($img,$meta) = @_;
  my $header=$meta{'header'};
  my @kw=unique(@{$meta{'keywords'}}); 
  my $comment=$meta{'comment'};
  my ($path,$imgname)=($1,$2);
  my $metafile=$path.".metadata/".$imgname.".meta";
  $kwstr=join("\n", at kw);
   print MFILE "$header\n\n[keywords]\n$kwstr\n\n[comment]\n$comment\n#end\n";
  close MFILE;

sub unique {
  my %seen=(); my $item; my @uniq;
  foreach $item (@_) {
    push(@uniq, $item) unless $seen{$item}++;
  return @uniq;

sub mkdirhier {
  my $dir=$_[0];
  my @components=split /\//, $dir;
  my $path="";
  if ($dir =~/^\//) {$path='/'; shift(@components);}
    foreach $component (@components) {
    mkdir($path) unless -e $path;


=head1 NAME



B<gqv2bins> [ B<--add> | B<--remove> ] imagefile


This script is useful if you have lots of pictures into a directory structure
and you want to add only some of them to a web album preserving the initial

To be used in conjunction with L<gqview(1)> and L<bins(1)>.
Change $imgdir, $targetdir_base and $albumdir_base according to your 
preferences. Add this script with appropriate options to 
Edit->Preferences->Editors in gqview:

For adding a picture to the album:
Menu name:      "Add to bins" 
Command line:   "gqv2bins -a %p"

For removing a picture from the album:
Menu name:      "Remove from bins" 
Command line:   "gqv2bins -r %p"

This way you can add ar remove one file (or all the selected files) with one 
click directly from gqview. 

=head1 OPTIONS


=item B<--add> 

Add an image to the source directory to be used with bins: 
Links the argument (image under $imgdir) into the mirror directory structure
under $targetdir_base. Also sets the bins description field of the linked image 
to the gqview comment of the original image and ads the keyword "bins" to the
gqview keywords. A new field named "keywords" is created in the xml file 
corresponding to the image and is set to the list of gqview keywords. Thus, the 
keywords can be used in searches from bins. Just add "keywords" in the 
"searchFields" parameter in binsrc.

Example: the image $imgdir/canon/2004/braunschweig/someimage.jpg will be linked
to $targetdir_base/canon/2004/braunschweig/someimage.jpg and the gqview comment
will be transfered to the description field in file 
$targetdir_base/canon/2004/braunschweig/someimage.jpg.xml. After you add all
your images to the album source you can create the album  with bins
$targetdir_base $albumdir_base.

=item B<--remove> 

Remove an image from the album:
Deletes the previously created link, corresponding xml file and the album
files. It also removes the "bins" keyword from the gqview keyword list.

Note: This action is potentially destructive. Please make sure you set 
$imgdir, $targetdir_base, and $albumdir_base to their correct values.



Copyright 2005, Dragos Constantinescu.  All rights reserved.  This program is 
free software. It may be used, redistributed, and/or modified under  the same
terms as Perl itself.

=head1 AUTHOR

Dragos Constantinescu, dragos at venus.nipne.ro


More information about the Bins mailing list