How to dirty a 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?".
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

How to dirty a font

Post by FrereTuck »

Hi guys,

I'm trying to "replicate" the look and feel of an old (circa 1981) print with a font that looks almost (to me) the same.
Image
The problem is I don't have the "grain" of the old printed media.
Image
Ok, the font is not that good (I used What's the Font Android application), but I hope you get the idea.

I had a look at Fred's scripts but I didn't manage to find one to get what I'd like.
I thought of using erode, but I don't know how to apply it to each letter.

If you ever have an idea, please let me know.

Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to dirty a font

Post by snibgo »

What version of IM? I assume v6. If v7, use "magick" instead of "convert". What platform? I assume Windows.

Many methods are possible, such as this (Windows BAT format, for IM v6.)

Code: Select all

convert ^
  flowRoot3688.png -alpha extract ^
  ( +clone ^
    -fill gray(50%%) -colorize 100 ^
    +noise Gaussian ^
    -channel R -separate +channel ^
    -blur 0x1 ^
    -auto-level ^
  ) ^
  -evaluate-sequence Mean ^
  -threshold 50%% ^
  -define connected-components:area-threshold=20 ^
  -define connected-components:mean-color=true ^
  -connected-components 4 ^
  -threshold 50%% ^
  -blur 0x0.5 ^
  ( +clone ^
    -fill Black -colorize 100 ^
  ) ^
  +swap ^
  -compose CopyOpacity -composite ^
  noisyFont.png
I prefer to work in black and white, rather than opaque and transparent, so I extract alpha at the start and copy opacity at the end.

I create a clone of the image, and replace the pixels with Gaussian random, use just the red channel, and blur it, (adjust the blur sigma from 1 if you want) and auto-level.

I take the mean of the text image and the noise, and threshold to 50% to get white characters on black background. However, there will be some small patches of black within the white characters, and small patches of white within the black background. Connected-components, followed by another threshold, removes these.

Now we have entirely white characters on black background. A small blur gives an antialias. (There are "proper" ways of doing this, but they are more complex.) If you don't want the antialias, remove that blur.

Then we create an entirely black image and copy the opacity to it.

Image

My command is rather complex. I suspect there is a simpler method.
snibgo's IM pages: im.snibgo.com
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: How to dirty a font

Post by FrereTuck »

Thanks a lot for the explanation, and sorry for the lack of details.
I am working on Ubuntu with ImageMagick 6.8.9-9 Q16 x86_64 2017-07-31 http://www.imagemagick.org
I will try to understand step by step and to play with the parameters.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to dirty a font

Post by snibgo »

For bash, replace the characters at line ends from "^" to "\", replace the doubled %% with single %, and escape the parentheses thus: \( \).
snibgo's IM pages: im.snibgo.com
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: How to dirty a font

Post by FrereTuck »

Thanks for the tips.
I now have:

Code: Select all

#!/bin/sh
convert \
  flowRoot3688.png -alpha extract \
  \( +clone \
    -fill gray\(50%\) -colorize 100 \
    +noise Gaussian \
    -channel R -separate +channel \
    -blur 0x1 \
    -auto-level \
  \) \
  -evaluate-sequence Mean \
  -threshold 50% \
  -define connected-components:area-threshold=20 \
  -define connected-components:mean-color=true \
  -connected-components 4 \
  -threshold 50% \
  -blur 0x0.5 \
  \( +clone \
    -fill Black -colorize 100 \
  \) \
  +swap \
  -compose CopyOpacity -composite \
  noisyFont.png
But the end result is a 1kb image. I will try to find my mistake.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to dirty a font

Post by snibgo »

Your bash version of the command works fine for me in bash, with IM v6.9.5-3.

Connected-components are fairly new, possibly after your v6.8.9-9. Try removing those three lines, and the following "-threshold".

Incidentally, if you want to increase the noise, change the line from

Code: Select all

-evaluate-sequence Mean
to

Code: Select all

-compose Mathematics -define compose:args=0,0.6,0.4,0 -composite
For very extreme noise:

Code: Select all

-compose Mathematics -define compose:args=0,0.9,0.1,0 -composite
snibgo's IM pages: im.snibgo.com
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: How to dirty a font

Post by FrereTuck »

I updated my Ubuntu machine to 17.10 in order to test these commands, but I now face a

Code: Select all

convert: error while loading shared libraries: libgvc.so.6: cannot open shared object file: No such file or directory
.
So I'll try to solve this and then will be back with the results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to dirty a font

Post by fmw42 »

You could also use -spread 1 and then blur a little and threshold

Code: Select all

convert flowRoot3688.png -spread 1 flowRoot3688_spread1.png

or

convert flowRoot3688.png -spread 1 -blur 0x1 -threshold 50% flowRoot3688_spread1b.png
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: How to dirty a font

Post by FrereTuck »

I will try that. I don't know why my result is so different from snibgo's one.
I will investigate now that imagemagick is up and running again.
Thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to dirty a font

Post by anthony »

Added the simpler spread technique to "Compound Fonts" section of IM Examples
http://www.imagemagick.org/Usage/fonts/#dirty_print

May take a hour or so to appear online.


The Compound Fonts Section is one of the oldest of ImageMagick Examples, and basically explores simple techniques of modifying a simple image (drawn font) to produce various effects. It was nice to add a new example to that section.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to dirty a font

Post by fmw42 »

Unix users could also use my script, disperse, for a large variety of effects. Here are few.

input:
Image


Code: Select all

disperse -s 1 -d 1 -c 1  flowRoot3688.png test1.png
Image

Code: Select all

disperse -s 2 -d 2 -c 5  flowRoot3688.png test2.png
Image

Code: Select all

disperse -s 2 -d 5 -c 2  flowRoot3688.png test3.png
Image

Code: Select all

disperse -s 1 -d 2 -c 2  flowRoot3688.png test4.png
Image
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: How to dirty a font

Post by FrereTuck »

Thanks a lot, guys, I will try that today.
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: How to dirty a font

Post by FrereTuck »

My tries are pretty encouraging.
For the time begin, I had good results with

Code: Select all

disperse -s 1 -d 2 -c 2  flowRoot3688.png test4.png
As for the sample, I just don't get why

Code: Select all

convert -size 320x100 -font Candice -pointsize 72 -annotate +25+65 'Anthony' \
          -spread 1 -blur 0x1 -threshold 50% -blur 0x1 font_dirty_print.jpg
gives me this error:

Code: Select all

convert: no images defined `font_dirty_print.jpg' @ error/convert.c/ConvertImageCommand/3258.
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Ubuntu 17.10
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to dirty a font

Post by snibgo »

Because you have no input image. Nothing in your command reads an image or creates one.
snibgo's IM pages: im.snibgo.com
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

Re: How to dirty a font

Post by FrereTuck »

This next command has no input image but works:

Code: Select all

convert -size 320x100 xc:lightblue -font Ubuntu -pointsize 72 -fill navy  -annotate +25+65 'Anthony' -blur 0x3 font_fuzzy.jpg
Post Reply