Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Don't ask to ask, just ask
 
PerlMonks  

Image and Text Watermarked Letters

by zentara (Archbishop)
on Nov 25, 2008 at 17:49 UTC ( #725895=sourcecode: print w/ replies, xml ) Need Help??

Category: Fun Stuff
Author/Contact Info zentara of perlmonks
Description: Just a simple script to show how to add semi-transparent images and text to an image, or in this case a blank US letter sized paper.... ready to run off reams of copies. This particular example is for Perl. The Programming Republic of Perl stamp is base64encoded into the script.
#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
use MIME::Base64;

#Usage: Script.pl base_image 
#my $file = shift or die "need an image $!\n";
#my $image = Image::Magick->new;
#my $rc = $image->Read($file);

my $image = Image::Magick->new;
$image->Set(size=>'612x792');  # US letter 8.5 x 11 inches
my $rc = $image->Read("xc:white");

my $wimage = Image::Magick->new(magick=>'png');
my $stamp = get_stamp();
$wimage->BlobToImage($stamp);
#$wimage->Write('stamp.png'); #if you want to examine it

$rc = $image->Composite(
     gravity => "Center", 
     compose=>'Dissolve',
     image => $wimage,
      opacity => '5%',  #how much transparency
      tile  => 1,  
      );

foreach my $pos qw(North Center South){
$image->Annotate(pointsize => 36,
         fill      => '#00000008', #last 2 digits transparency in hex 
+ff=max
         text      => 'Just Another Perl Hacker',
         gravity   => $pos );
}

$image->Write("$0.png");

exit;

sub get_stamp{

return decode_base64( 
'iVBORw0KGgoAAAANSUhEUgAAAGEAAABhBAMAAAA0KNKQAAAAG1BMVEX///8AAAAhISFCQ
+kJSUlJ7
e3ucnJzw8PD////JTe+VAAAAAXRSTlMAQObYZgAACJ5JREFUeF7FmEuPuzoSxWdzb6/LMg
+lbe0yH
9UjzAWyZhOWAcMLyJsqDZacVHltQCPWxxw6kn//HXYw0R62WOuHHOVXGXU7+8b/RS32yql
+/+LlBe
JLvrn+ZvQU+G873mXGu9VuxQ//b6UgZKnNBpMFwk4vQboOYqKAaUDTJioVoF5NfJSi5XQ9
+P6kLcA
lrg1V0o2L79y4AUmYesl8dZHqxb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fGjQBxYdFCayqDJR4I8pjOfXlBD/UGMEKibHRFpsB
+uBXj2I
dDJtLdlg4+AGb25iIqaguPDfy/hcCHr4rhtwRREZcM5wlJ4/iD/cS+fBdyZv6jnnHg6Mk2
+yO28G1
/v3c9xSE1hJiRKiOD11AAq1KxkFOb344xD1tZ9bDEV14L2JwqZiEABE4C92bBWL6/PEoam
+MDQUT5
XgfjzpVwgdgDUERvMwGPWPR+HX1DgJMYr8AKiw/egK3b4++xBOJicMj7Afl+3+102vAR1e
+zTmZoV
OOl1QgbGLcEsMK0PqT8R+zk+dIXAbcU1W4q9c5i0Xb58Oel/OEuqyJEsourNGQd30v9kou
+f4efUU
0Q32b2nP2lp80uXd5OZNftd897Ae6MoCPzPpgPYivvBw6w/4ZvEVcJW8Hz+hhZkEr/XfYr
+oqvpns
+COyzzqv2BrSzR4Et436rjKYLtjG0M5xm0NPJyBJncV3nWWIThJIC34rYICpMDFtjO+5xq
+ENMHcE
eDgSV+/5Z98d1EQWiAMc3Fi4E9C4h1P9/AN6LViOPSC2s6b1ACUU2BP+q68aKiGf8Yh4ts
+HmEL4W
uKfcRvqFSp6KxkZX/jW82URc/BpwLv8Sii8bdNpzkQob6Teq11wYrRRX2ii++ltfytQHxo
+n7Yccp
0e+Zp7qsqkv9Yg3+P/ovrxusJ+JGDQIAAAAASUVORK5CYII=');
}

Comment on Image and Text Watermarked Letters
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://725895]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-04-18 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (473 votes), past polls