$ brew install keyz/tap/comicsans
# pass text as an argument
$ cs 'Write something here and get a png back'
File generated: ./write-something-here-and-get-a-png-back.png
# or pass text through a pipe
$ echo -n 'seems legit' | cs -
File generated: ./seems-legit.png
Fitting text to a container is not a trivial problem. On web this can be done with an off-screen render-measure-resize loop, like STRML/textFit
(which powers https://keyan.io/pink).
Without a browser environment we need a rendering engine with good typography support. Turns out SwiftUI's minimumScaleFactor
handling is pretty good at this:
- Text goes to an off-screen SwiftUI text view, with an arbitrarily large font size and high
minimumScaleFactor
- SwiftUI resizes the text to fit the container
ImageRenderer
rasterizes the view into a PNG bitmap
OVERVIEW: cs (comic sans) for :pink-slack-emoji:
Converts text to pink comic sans slack emoji. https://github.com/keyz/comicsans
USAGE: Pass text as an argument:
$ cs 'Write something here and get a png back'
Or pass text through a pipe:
$ echo -n 'seems legit' | cs -
ARGUMENTS:
<text> Text to convert
OPTIONS:
-p, --padding <padding> Padding (values: 0, 4, 8, 12, 16, 20, 24) (default: 4)
-h, --horizontal <horizontal>
Horizontal alignment (values: leading, center,
trailing; default: leading)
-v, --vertical <vertical>
Vertical alignment (values: top, center, bottom;
default: center)
-o, --output <output> Output directory
--version Show the version.
--help Show help information.