[Bins] Add images from gqview

Dragos Constantinescu d.constantinescu at tu-bs.de
Mon Nov 21 09:19:09 GMT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi,

I am happy you consider to provide it with BINS. GPL is fine :). I 
attached a new version. Now it adds the keyword "bins" to the qgview 
keyword list, can remove previously added images and has a new name.

Cheers,

________________________

         Dragos                                PGP key ID: A0887098

2005-11-21
10:01am



On Sun, 20 Nov 2005, Jérôme SAUTRET wrote:


> Hi,
>
> Thanks for you contribution. I'd like to provide it with BINS, in the
> tools subdir, can you tell me the condition of distribution of your
> script (GPL seems fine ;-) ?
>
> --
> Jérôme SAUTRET (Jerome @ SAUTRET.org)           http://SAUTRET.org
> Key 0x95D463F3 fingerprint 3B69 3B60 4D32 B8DF 2BF3 8035 5036 D41A 95D4 63F3
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQFDgZEUunb5IaCIcJgRAsuBAJ4vJh1UG4PBJdKz8KO904AxpyjUiACfctTJ
vSmLMbK6s06v+6JWeUXQgtw=
=D8z+
-----END PGP SIGNATURE-----
-------------- next part --------------
#!/usr/bin/perl -w
use Getopt::Long;

$add='';
$remove='';
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
#############################################


$file =~/$imgdir(.+\/)(.+?)$/;
$targetdir=$targetdir_base.$1;
$link_name=$targetdir.$2;
$albumfile=$albumdir_base.$1.$2;
$xml_name=$link_name.'.xml';
$albumfile=~/^(.+)(\..+?)$/;
@albumfiles=glob($1.'_*');
push @albumfiles, $albumfile.'.details.html';

%meta=read_meta($file); 
#$header=$meta{'header'}; 
@kw=@{$meta{'keywords'}}; $comment=$meta{'comment'};

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

if ($add) {
  push @{$meta{'keywords'}}, 'bins';
  write_meta($file,\%meta);
  $targetdir=~s/ /\\ /g;$file=~s/ /\\ /g;$link_name=~s/ /\\ /g;
  system "mkdirhier $targetdir
          chmod a+rx $targetdir
          ln -s $file $link_name
          /usr/local/bin/bins_edit --description \"$comment\" $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";
  @{$meta{'keywords'}}=();
  foreach $kwrd (@kw) {push @{$meta{'keywords'}},$kwrd unless $kwrd eq 'bins'};
  write_meta($file,\%meta);
  unlink(@albumfiles,$link_name,$xml_name);
  print "run bins $targetdir_base $albumdir_base \nto reflect the changes\n\n";
}

sub read_meta {
  my $img=$_[0];
  $img=~/^(.+\/)(.+?)$/;
  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='';
  open(MFILE,"<$metafile");
  chomp($meta{'header'}=<MFILE>);
  while (<MFILE>){
    chomp(my $line=$_);
    next if $line eq '';
    if ($line=~/^\[(.+)\]$/){
      $field=$1;
      next;
    }
    next if $field eq '';
    last if $line =~/#end/;
    if ($field eq "keywords") {
      push @keywords,$line; 
    } elsif ($field eq "comment") {
      $meta{'comment'}.="$line\n";
    }
  }
  
  close MFILE;
  return %meta;
}

sub write_meta {
  my ($img,$meta) = @_;
  my $header=$meta{'header'};
  my @kw=unique(@{$meta{'keywords'}}); 
  my $comment=$meta{'comment'};
  $img=~/^(.+\/)(.+?)$/;
  my ($path,$imgname)=($1,$2);
  my $metafile=$path.".metadata/".$imgname.".meta";
  #$metafile='meta.test';
  $kwstr=join("\n", at kw);
  mkdir($path.'.metadata');
  open(MFILE,">$metafile");
   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;
}

__END__

=head1 NAME

gqv2bins

=head1 SYNOPSIS

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

=head1 DESCRIPTION

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
structure.

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 to Edit->Preferences->Editors in gqview.

=head1 OPTIONS

=over

=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.

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.

=back

=head1 COPYRIGHT

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

=cut



More information about the Bins mailing list