Text stroke + shadow + PNG transparency + label interword-spacing fit

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
queensoft
Posts: 14
Joined: 2014-02-14T09:12:48-07:00
Authentication code: 6789

Text stroke + shadow + PNG transparency + label interword-spacing fit

Post by queensoft »

Final image is like this (used as watermark for video):
- transparent PNG, 1920x1080, text at bottom
- text is automatically fit to image width, using 'label' and 'interword-spacing'
- text is offset from border, using 'bordercolor transparent' and 'border'
- text has stroke
- text also needs to have shadow (blur, drop shadow, doesn't really matter which one)
But, every time I try to add this shadow, I end up with completely white image or loss of transparency
Also, I want to create image using one single command line.
I use ImageMagick-7.0.1-Q16.
Command line is like this:

Code: Select all

convert.exe -size 1890x1050 xc:none -font Arial -size 1890x -fill rgb(255,255,255) -stroke #0d0707 -background transparent -gravity South -interword-spacing 500  label:"www.google.com (555)123-4567" -bordercolor transparent -border 15x15  -composite +repage -depth 8 output.png
I have tried numerous examples of 'clone', but got nowhere.
What am I doing wrong ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Text stroke + shadow + PNG transparency + label interword-spacing fit

Post by snibgo »

Have you looked at http://www.imagemagick.org/Usage/blur/#shadow ? That shows you how to create shadows when you have opaque letters on a transparent background.

You already have an image, output.png, so you can put a shadow behind it (Windows BAT syntax):

Code: Select all

convert output.png ^
  ( +clone   -background navy   -shadow 80x3+3+3 ) +swap ^
  -background none   -layers merge +repage  s.png
If you want the whole thing in one command, that's easy. The output of the first convert is an image, and that's directly used by the second command, so just merge them:

Code: Select all

convert.exe -size 1890x1050 xc:none -font Arial -size 1890x -fill rgb(255,255,255) -stroke #0d0707 -background transparent -gravity South -interword-spacing 500  label:"www.google.com (555)123-4567" -bordercolor transparent -border 15x15  -composite +repage -depth 8 ^
  ( +clone   -background navy   -shadow 80x3+3+3 ) +swap ^
    -background none   -layers merge +repage  s.png
snibgo's IM pages: im.snibgo.com
queensoft
Posts: 14
Joined: 2014-02-14T09:12:48-07:00
Authentication code: 6789

Re: Text stroke + shadow + PNG transparency + label interword-spacing fit

Post by queensoft »

Holy cow !!! Thanks a lot !!
Yes, I looked at 'shadow', but I was always adding the shadow before '-composite +repage'
The same thing with 'clone', I was adding it before the final step ('-composite +repage')
Thank you very much, problem solved.
Later edit: hmm, one small problem: final image resolution is not 1920x1080 anymore, but 1932x1092.
I'm pretty sure it's an easy fix.
Later later edit: fixed size, just decreased first one: '-size 1878x1038'
Not sure why this problem occured, but I'm not that curious :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text stroke + shadow + PNG transparency + label interword-spacing fit

Post by fmw42 »

shadow extends the image to allow room for the shadow. you can just crop the image back to its original size if you want at the end of your command.
Post Reply