Outline text effect with -page not working with bitmap font

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
hagabaka
Posts: 5
Joined: 2011-01-25T00:58:30-07:00
Authentication code: 8675308

Outline text effect with -page not working with bitmap font

Post 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...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
hagabaka
Posts: 5
Joined: 2011-01-25T00:58:30-07:00
Authentication code: 8675308

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

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply