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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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');

Comments

Comments powered by Disqus