#!/usr/bin/perl # # watermark - add a watermark to a JPEG or PNG image (requires ImageMagick) # copyright (c) 2004-2007 by Ian Kluft # released under the GNU General Public License Version 2 # http://www.kluft.com/~ikluft/opensource/GPLv2.txt use strict; use Getopt::Long; my ( $file, $watermark, $comment ); GetOptions ( "watermark=s" => \$watermark, "comment=s" => \$comment ) or die "usage: $0 --watermark wm-file --comment text image-file ...\n"; foreach $file ( @ARGV ) { my ( $prefix, $suffix, $format, $file_orig ); if ( $file =~ /^(.*)(\.jpg|\.jpeg)$/i ) { $prefix = $1; $suffix = $2; $format = "jpeg"; } elsif ( $file =~ /^(.*)(\.png)$/i ) { $prefix = $1; $suffix = $2; $format = "png"; } else { die "$0: format not recognized\n"; } $file_orig = $prefix."-orig".$suffix; if ( ! rename ( $file, $file_orig )) { die "$0: rename failed on $file\n"; } if ( $format eq "jpeg" ) { system "composite -compose atop -dissolve 30 -gravity southeast -quality 99 $watermark $file_orig /proc/self/fd/1 | wrjpgcom -replace -comment '$comment' > $file"; } elsif ( $format eq "png" ) { system "composite -compose atop -dissolve 30 -gravity southeast -quality 99 $watermark $file_orig $file"; } else { die "$0: format $format not recognized\n"; } }