Page 1 of 1

Outline text effect with -page not working with bitmap font

Posted: 2013-05-06T20:11:10-07:00
by hagabaka
Hello,

A while ago I learned a way to generate outlined text here by shifting a colored copy of the text multiple times with -page. It works when I use a TrueType font

Code: Select all

convert \( -background transparent -fill '#ff0000' -font 'OpenSans-Regular.ttf' -pointsize 16 label:'V' \) \
        \( -background transparent -fill '#0000ff' -font 'OpenSans-Regular.ttf' -pointsize 16 label:'V' \) \
        -background transparent \
        -page -1-1 -clone 0 \
        -page -1+1 -clone 0 \
        -page +1+1 -clone 0 \
        -page +1-1 -clone 0 \
        -page +0+0 -clone 1 \
        -delete 0,1 -layers merge +repage png32:ttf.png
Image

But it doesn't when I use a PCF bitmap font:

Code: Select all

convert \( -background transparent -fill '#ff0000' -font 'unifont.pcf.gz' -pointsize 16 label:'V' \) \
        \( -background transparent -fill '#0000ff' -font 'unifont.pcf.gz' -pointsize 16 label:'V' \) \
        -background transparent \
        -page -1-1 -clone 0 \
        -page -1+1 -clone 0 \
        -page +1+1 -clone 0 \
        -page +1-1 -clone 0 \
        -page +0+0 -clone 1 \
        -delete 0,1 -layers merge +repage png32:pcf.png
Image

Anyone know why this is?

I'm sorry about the small size of the example images, but the PCF font I'm using is only available for this size, and it's the only PCF font I've found that works with imagemagick...

Re: Outline text effect with -page not working with bitmap f

Posted: 2013-05-06T20:54:26-07:00
by anthony
I believe PCF fonts are rendered using ghostscript. This may not have the same capabilities at the fonts rendered with the more freetype font rendering library.

Re: Outline text effect with -page not working with bitmap f

Posted: 2013-05-07T05:21:38-07:00
by hagabaka
But I thought those commands just rendered two copies of the text with transparent background, offset them and merged them together. The following set of commands do work. Are they significantly different from the one in the first post?

Code: Select all

character='V'
convert -background transparent -pointsize 16 -font unifont.pcf.gz \
        -fill '#550b0b' label:"$character" outline.png
convert -background transparent -pointsize 16 -font unifont.pcf.gz \
        -fill '#e9f9f9' label:"$character" body.png
convert -background transparent \
        -page -1-1 outline.png \
        -page -1+1 outline.png \
        -page +1+1 outline.png \
        -page +1-1 outline.png \
        -page +0+0 body.png \
        -layers merge +repage result.png
Image
body

Image
outline

Image
result

Re: Outline text effect with -page not working with bitmap f

Posted: 2013-05-07T23:11:28-07:00
by anthony
Okay I see what is going wrong...

-page is a global setting that only effect images being read in.. It does NOT effect cloned images!

To set the virtual canvas of an image in memory use -repage.

Code: Select all

convert \( -background transparent -fill '#ff0000' -font 'OpenSans-Regular.ttf' -pointsize 16 label:'V' \) \
        \( -background transparent -fill '#0000ff' -font 'OpenSans-Regular.ttf' -pointsize 16 label:'V' \) \
        -background transparent \
        \( -clone 0 -repage -1-1 \) \
        \( -clone 0 -repage -1+1 \) \
        \( -clone 0 -repage +1+1 \) \
        \( -clone 0 -repage +1-1 \) \
        -delete 0 -reverse -layers merge +repage png32:ttf.png
Note I only delete the zero or outline image, and then reverse the sequence of all images so that the 'fill' image is last.

Also there are now better ways of doing this that was not available when I created that example. It is called morphology Dilate
http://www.imagemagick.org/Usage/morphology/#dilate

Code: Select all

convert -background none -fill blue -font 'OpenSans-Regular.ttf' -pointsize 16 label:'V' \
            -bordercolor none -border 1x1 \
            \( +clone  +level-colors red \
               -channel RGBA -morphology dilate diamond  +channel \) \
            -reverse -composite result.png
NOTE the +level-colors red is to recolor the original image from blue to red.

Normally I would use -fill red -colorize 100% but that appears to be broken in the latest release (it is re-coloring the alpha channel as well) -- I have submitted a bug report about it.