This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use Image::Magick; | |
# Input and output files | |
my $sourcefile = 'image-magick-step-1.jpg'; # blank name tag image (input filename) | |
my $texturefile = 'image-magick-step-2.jpg'; # pebbled texture image (input filename) | |
my $targetfile = 'image-magick-step-6.jpg'; # final composite image (output filename) | |
# Text values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Layer our textured shadow onto the blank name tag, using our mask layer as a stencil | |
$nametag->Composite( | |
image => $texture, | |
mask => $mask, | |
); | |
# Write the resulting image to a file | |
$nametag->Write($targetfile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Layer our blurred shadow onto our texture image | |
$texture->Composite( | |
image => $shadow, | |
compose => 'Dissolve', | |
opacity => $opacity, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create our shadow image | |
my $shadow = Image::Magick->new; | |
$shadow->Set( size => '503x339' ); | |
$shadow->ReadImage( 'canvas:black' ); | |
$shadow->Annotate( | |
font => $font, | |
pointsize => $size, | |
fill => 'white', | |
text => $name, | |
x => $x + $offsetx, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a mask (or stencil) image using the desired text | |
my $mask = Image::Magick->new; # Create a new image object | |
$mask->Set( size => '503x339' ); # Same size as blank name tag image | |
$mask->ReadImage( 'canvas:black' ); # Fill the image with black | |
$mask->Annotate( # Render the text on the image in white | |
font => $font, | |
pointsize => $size, | |
fill => 'white', | |
text => $name, | |
x => $x, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Position text so it's centered on the name tag | |
my $x = $startx - int($width / 2); | |
my $y = $starty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get dimensions of rendered text | |
my ($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance) = | |
$nametag->QueryFontMetrics( | |
font => $font, | |
pointsize => $size, | |
text => $name, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load image files for compositing | |
my $nametag = Image::Magick->new; | |
my $texture = Image::Magick->new; | |
$nametag->Read($sourcefile); | |
$texture->Read($texturefile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use Image::Magick; | |
# Input and output files | |
my $sourcefile = 'image-magick-step-1.jpg'; # blank name tag image (input filename) | |
my $texturefile = 'image-magick-step-2.jpg'; # pebbled texture image (input filename) | |
my $targetfile = 'image-magick-step-6.jpg'; # final composite image (output filename) | |
# Text values |