https://github.com/keyz/comicsans
cs (comic sans) for :pink-slack-emoji:
https://github.com/keyz/comicsans
Last synced: 5 months ago
JSON representation
cs (comic sans) for :pink-slack-emoji:
- Host: GitHub
- URL: https://github.com/keyz/comicsans
- Owner: keyz
- License: mit
- Created: 2024-08-23T16:18:40.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-02T07:36:37.000Z (over 1 year ago)
- Last Synced: 2026-02-01T14:44:08.243Z (6 months ago)
- Language: Swift
- Homepage:
- Size: 140 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# comicsans
## Install
```bash
$ brew install keyz/tap/comicsans
```
## Usage
```bash
# 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
```

## How does it work?
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`](https://github.com/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`](https://developer.apple.com/documentation/swiftui/environmentvalues/minimumscalefactor) handling is pretty good at this:
1. Text goes to an off-screen SwiftUI text view, with an arbitrarily large font size and high `minimumScaleFactor`
2. SwiftUI resizes the text to fit the container
3. [`ImageRenderer`](https://developer.apple.com/documentation/swiftui/imagerenderer) rasterizes the view into a PNG bitmap
## More options
```
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 to convert
OPTIONS:
-p, --padding Padding (values: 0, 4, 8, 12, 16, 20, 24) (default: 4)
-h, --horizontal
Horizontal alignment (values: leading, center,
trailing; default: leading)
-v, --vertical
Vertical alignment (values: top, center, bottom;
default: center)
-o, --output Output directory
--version Show the version.
--help Show help information.
```