#!/usr/pkg/bin/perl
# Author  :	Stefan Schumacher, <stefan[at]net-tex[dot]de>
# PGP     :   	0xB3FBAE33
# Purpose : 	composite 2 images to create a "signed" one	
# Created : 	Thu Dec  4 01:07:01 CET 2003	
# Needs   :    	ImageMagick (identify, composite)
# released under BSD License, I will not support non-free forks 
# like Public Domain, closed source, GPL or other
=man

NAME
	picsig.pl - add a sign to a picture		
SYNOPSIS
	picsig.pl [file]
	
DESCRIPTION

picsig.pl uses 2 ImageMagick programms (identify, composite)
to add the image [file] to the lower right corner of all *.jpg
in the current directory.

=cut
#filecontrol functions
# filenames
# array with all files, counter for number of files
my @allfiles = glob "*.jpg";
my ($sign)=@ARGV;

if($sign eq '-v'){
print "picsig.pl   version 0.1   20031206 \n(C) Stefan Schumacher <stefan\@net-tex\.de> http://www.net-tex.de\nreleased under BSD Licence \n";}

elsif($sign eq '-h' || $sign eq ''){
print "picsig.pl -v	  	: show version
picsig.pl -h	  	: show this   
picsig.pl foobar.gif	: add foobar.gif to each *.jpg at the lower right corner
			  writing the result to signed-*\n";
}
else{
	# get data of sign 
		my $sidentified = `identify $sign`;
   		my $dimensions = (split / /,$sidentified)[2];		
		@splitteddims   = split(/x/, $dimensions);
		$sigwidth=$splitteddims[0];		
		$temp=$splitteddims[1];
		@splitteddims2 = split(/\+/,$temp);
		$sigheight = $splitteddims2[0];
	# run through directory for each file
	for my $file (@allfiles)
	{
		# use ImageMagick identify to get dimensions of fotos
    		my $identified = `identify $file`;
   		my $dimensions = (split / /,$identified)[2];		
		@splitteddims   = split(/x/, $dimensions);
		$width=$splitteddims[0];		
		$temp=$splitteddims[1];
		@splitteddims2 = split(/\+/,$temp);
		$height = $splitteddims2[0];
		$cwidth=$width-$sigwidth;
		$cheight=$height-$sigheight;
		$cgeom='+'.$cwidth.'+'.$cheight;
		my $identified = `composite -geometry $cgeom $sign $file signed-$file`;
  	}#for
}#else