Skip to main content

Watermarks with Perlmagick

Since in a couple of days I'll forget it all, here's a snippet to do watermarking with Perlmagick:

#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
my $text='ABCDEF 123';
my $x;
my $null=Image::Magick->new;
my $img=Image::Magick->new;
$null->Set(size=>'340x170');
$x=$null->ReadImage('xc:white');
warn "$x" if "$x";
$x=$null->Annotate(text=>$text,
  geometry=>'+10+20',
  font=>'/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf',
  fill=>'black',
  gravity=>'North',
  pointsize=>50);
warn "$x" if "$x";
$null->Rotate(degrees=>45, background=>'white');
$null->Set(alpha=>'Activate');
$null->Transparent(color=>'white');
$x=$img->ReadImage('base.jpg');
warn "$x" if "$x";
$img->Composite(image=>$null,
  compose=>'Dissolve',
  gravity=>'Center',
  caption=>'TEST',
  opacity=>'30%');
$img->Write('test.jpg');