views:

608

answers:

1

I'm trying to annotate some text onto a base image with a dropshadow. I don't like the results I get from using the -shadow option, so I'm putting down the text, blurring it, then putting down the text again in white, a few pixels offset from the shadow. Here's the command I'm using:

convert base_image.jpg \
        -font TT0590M_.ttf \
        -fill gray30 \
        -annotate +0+0 '' -gravity North \
        -annotate +72+32 'ABCDEFGHIJKLM' \
        -blur 0x4 \
        -fill white \
        -annotate +72+27 'ABCDEFGHIJKLM' \
        combined.png

My problem is that the -blur option is blurring not only the first layer of text, but the underlying base image as well. I only want the first layer of text to blur, not the base image.

I read up a little on using stacks and tried to isolate the first layer of text and the blur command using \( \) around that part, such as in the following:

convert base_image.jpg \
        -font TT0590M_.ttf \
        -fill gray30 \
        -annotate +0+0 '' -gravity North \
        \( -annotate +72+32 'ABCDEFGHIJKLM' \
        -blur 0x4 \) \
        -fill white \
        -annotate +72+27 'ABCDEFGHIJKLM' \
        combined.png

The results are the same - both the text shadow and the underlying base image are getting blured. I'm afraid I'm not having much luck understanding stacks or what other commands I should be using to get the effect I'm after.

Any help would be appreciated.

Thanks.

+2  A: 

As so often happens, I've continued to bang away at this since posting the question and I've managed to solve it on my own.

The important change is that I started with a blank, transparent canvas instead of starting with the base image. After I get the text right, I insert the base image into the stack, swap the order of the two images in the stack, and then composite them with a compose type of "screen", which lays the one overtop of the other.

One other note of import: the -channel RGBA is needed so that the blurring works in conjunction with the transparency of the text layer, due to a peculiarity in the way that IM works. Why this is necessary is explained on this page.

Also, on Windows systems (.bat file instead of shell script), the single quotes need to be double quotes and the backslashes "\" need to be carets "^", or it all comes crashing down.

The script below is the final, working result (*nix version):

convert  \
    -size 500x500 xc:transparent \
    -font TT0590M_.ttf \
    -annotate +0+0 '' -gravity North \
    -fill gray30 \
    -annotate +75+35 'ABCDEFGHIJKLMNOPQR\nABCDEFGHIJKLMNOPQR' \
    -channel RGBA \
    -blur 0x4 \
    -fill white \
    -annotate +72+30 'ABCDEFGHIJKLMNOPQR\nABCDEFGHIJKLMNOPQR' \
    -insert 0 base_image.jpg \
    -swap 0,1 \
    -composite -compose screen \
    combined.png
Yardboy