We’ll be using this mask in our final step to spray bits of one image onto another while blocking out other bits.
Okay, now we’re going to construct our shadow.
This is what we’ll eventually composite with our text layer to give our name tag the 3-D look that we want.
To create this shadow, we need to construct a new image that looks a lot like a mask but really isn’t.
The process is very similar to making our mask above.
We want our shadow to be shaped like our text, so we again build an image with white text on a black background (though we could just as easily use a brown or purple background, or anything else we feel like):But this time we do two things differently.
We offset the text a little, in this case moving it down vertically by two pixels.
Then we apply a Gaussian blur effect to the image, using a couple of variables that affect the degree to which the image gets blurred (play around with those values to see what happens).
This gives us the following result:Our shadow layer, stored in the $shadow objectLike I said, while this looks very similar to our mask image, it’s not exactly the same sort of thing.
What we’re going to do with it — and this is where the magic really starts to happen — is layer a translucent version of it on top of our texture image.
The code to do this is very simple:And that gives us the following image:Our composite shadow/texture layer, now stored in the $texture objectWe now have a composite image that looks like bright fuzzy letters projected onto a pebbled charcoal wall.
The fact that the texture is only faintly visible is the result of our $opacity parameter, which we could easily dial up or down, depending on the effect we wanted.
Now we’re ready for the final step.
We take that stencil from way back and spray our composite shadow layer through it onto our original blank name tag:We write the result to the file system, and voilà!.Here’s our final image, looking quite fine:Our final composite image (image-magick-step-6.
jpg)There’s no doubt a way to do this in fewer steps, but what we have here was certainly acceptable for my purposes and not all that difficult.
If you try this code out with your own images, I’d suggest spending time playing around with the values of the initial parameters, and with different colors for the shadow layer.
You might be surprised what you end up with!Hellfire bevel: $offsetx = -2, $offsety = -2, $sigma = 2, $opacity = ‘85%’, $shadow->ReadImage( ‘canvas:brown’ )In the end, my script was a little more complicated than what I’ve presented here, giving users a way to input a name and also choose from different image sizes with various slogans.
But the code above is where the magic (or rather, the Magick!) all happens.
ResourcesImageMagick: free image processing softwareImage::Magick: Perl interface to ImageMagickName Tag Generator: the complete script on GithubShare the Gospel: the script in action.