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

Overlay semi-transparent text on image using Image::Magick

by GrandFather (Saint)
on Sep 15, 2005 at 11:33 UTC ( #492171=snippet: print w/replies, xml ) Need Help??
Description: This code snippet demonstrates how to overlay translucent text on an image using Image::Magick. It draws the text using Annotate to an overlay image with a neutral background, then uses Composite's Hardlight operation to merge the overlay image into the destination image.
use strict;
use warnings;
use Image::Magick;

my $image = Image::Magick->new ();
my $over = Image::Magick->new();

$image->ReadImage ('x.JPG');
$over->Set(size=> "1200x200");
$over->ReadImage('xc:#808080'); # Nochange colour for Hardlight
my $err = $over->Annotate
  (
  pointsize => 200,
  text => 'Hello World',
  gravity=>'center',
  stroke => '#C0C0C0', # Increase to make stroke more white
  fill => '#505050', # Decrease to make fill more black
  font => '@C:/WINDOWS/Fonts/times.TTF', # Omit for default font
  );
print $err if $err;

$image->Composite (compose=>'Hardlight', image=>$over,gravity=>'center
+');
$image->Write ('xb.jpg');
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2021-10-22 17:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?