Skip to content

Commit

Permalink
Add text
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Oct 18, 2018
1 parent e43659e commit 7447b20
Show file tree
Hide file tree
Showing 96 changed files with 90,126 additions and 12 deletions.
20 changes: 16 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
APP=gif
NAME := yeetgif
REPOSITORY := quay.io/sergey_grebenshchikov/$(NAME)
VERSION := 1.14.0
VERSION := 1.15.0
VERSION_COMMIT := $(VERSION)-$(shell printf "%s" "$$(git rev-parse HEAD)" | cut -c 1-8)

PACKAGES := $(shell go list -f {{.Dir}} ./...)
Expand Down Expand Up @@ -34,7 +34,7 @@ release: zip README.md
hub release create $(VERSION) -m "$(VERSION)" -a release/$(APP)_$(VERSION)_osx_x86_64.tar.gz -a release/$(APP)_$(VERSION)_windows_x86_64.zip -a release/$(APP)_$(VERSION)_linux_x86_64.tar.gz -a release/$(APP)_$(VERSION)_osx_x86_32.tar.gz -a release/$(APP)_$(VERSION)_windows_x86_32.zip -a release/$(APP)_$(VERSION)_linux_x86_32.tar.gz -a release/$(APP)_$(VERSION)_linux_arm64.tar.gz

README.md: binary examples
<README.template.md subst USAGE_chop="$$($(APP) chop -h 2>&1)" USAGE_erase="$$($(APP) erase -h 2>&1)" USAGE_roll="$$($(APP) roll -h 2>&1)" USAGE_wobble="$$($(APP) wobble -h 2>&1)" USAGE_pulse="$$($(APP) pulse -h 2>&1)" USAGE_zoom="$$($(APP) zoom -h 2>&1)" USAGE_shake="$$($(APP) shake -h 2>&1)" USAGE_woke="$$($(APP) woke -h 2>&1)" USAGE_fried="$$($(APP) fried -h 2>&1)" USAGE_hue="$$($(APP) hue -h 2>&1)" USAGE_tint="$$($(APP) tint -h 2>&1)" USAGE_resize="$$($(APP) resize -h 2>&1)" USAGE_crop="$$($(APP) crop -h 2>&1)" USAGE_optimize="$$($(APP) optimize -h 2>&1)" USAGE_compose="$$($(APP) compose -h 2>&1)" USAGE_crowd="$$($(APP) crowd -h 2>&1)" USAGE_nop="$$($(APP) nop -h 2>&1)" USAGE_meta="$$($(APP) meta -h 2>&1)" USAGE="$$($(APP) -h 2>&1)" VERSION="$(VERSION)" APP="$(APP)" >README.md
<README.template.md subst USAGE_text="$$($(APP) text -h 2>&1)" USAGE_chop="$$($(APP) chop -h 2>&1)" USAGE_erase="$$($(APP) erase -h 2>&1)" USAGE_roll="$$($(APP) roll -h 2>&1)" USAGE_wobble="$$($(APP) wobble -h 2>&1)" USAGE_pulse="$$($(APP) pulse -h 2>&1)" USAGE_zoom="$$($(APP) zoom -h 2>&1)" USAGE_shake="$$($(APP) shake -h 2>&1)" USAGE_woke="$$($(APP) woke -h 2>&1)" USAGE_fried="$$($(APP) fried -h 2>&1)" USAGE_hue="$$($(APP) hue -h 2>&1)" USAGE_tint="$$($(APP) tint -h 2>&1)" USAGE_resize="$$($(APP) resize -h 2>&1)" USAGE_crop="$$($(APP) crop -h 2>&1)" USAGE_optimize="$$($(APP) optimize -h 2>&1)" USAGE_compose="$$($(APP) compose -h 2>&1)" USAGE_crowd="$$($(APP) crowd -h 2>&1)" USAGE_nop="$$($(APP) nop -h 2>&1)" USAGE_meta="$$($(APP) meta -h 2>&1)" USAGE="$$($(APP) -h 2>&1)" VERSION="$(VERSION)" APP="$(APP)" >README.md

examples: doc/terminal.gif doc/roll.gif doc/wobble.gif doc/pulse.gif doc/zoom.gif doc/shake.gif doc/woke.gif doc/fried.gif doc/hue.gif doc/tint.gif doc/compose.gif doc/crowd.gif doc/erase.gif

Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Composable GIF effects CLI, with reasonable defaults. Made for custom Slack/Disc
- [crowd](#crowd)
- [erase](#erase)
- [chop](#chop)
- [text](#text)
- [nop](#nop)
- [meta](#meta)
- [Licensing](#licensing)
Expand All @@ -43,14 +44,14 @@ Or [download the binary](https://github.com/sgreben/yeetgif/releases/latest) fro

```sh
# Linux
curl -LO https://github.com/sgreben/yeetgif/releases/download/1.14.0/gif_1.14.0_linux_x86_64.tar.gz | tar xz
curl -LO https://github.com/sgreben/yeetgif/releases/download/1.15.0/gif_1.15.0_linux_x86_64.tar.gz | tar xz

# OS X
curl -LO https://github.com/sgreben/yeetgif/releases/download/1.14.0/gif_1.14.0_osx_x86_64.tar.gz | tar xz
curl -LO https://github.com/sgreben/yeetgif/releases/download/1.15.0/gif_1.15.0_osx_x86_64.tar.gz | tar xz

# Windows
curl -LO https://github.com/sgreben/yeetgif/releases/download/1.14.0/gif_1.14.0_windows_x86_64.zip
unzip gif_1.14.0_windows_x86_64.zip
curl -LO https://github.com/sgreben/yeetgif/releases/download/1.15.0/gif_1.15.0_windows_x86_64.zip
unzip gif_1.15.0_windows_x86_64.zip
```

**NOTE**: To use the `optimize` command, you'll also need the [`giflossy`](https://github.com/kornelski/giflossy) fork of `gifsicle` installed:
Expand Down Expand Up @@ -99,6 +100,7 @@ Commands:
crowd (⟃ ͜ʖ ⟄) ͜ʖ ͡°)( ° ͜ʖ( ° ͜ʖ °)
erase ( ͡° ͜ʖ ͡°)=ε/̵͇̿̿/'̿̿ ̿ ̿ ̿ ̿ ̿
chop ✂️( ͡°Ĺ̯ ͡° )🔪
text 🅰️乁(˵ ͡☉ ͜ʖ ͡☉˵)┌🅱️
nop 乁(ᴗ ͜ʖ ᴗ)ㄏ
meta (🧠 ͡ಠ ʖ̯ ͡ಠ)┌
Expand Down Expand Up @@ -392,6 +394,27 @@ Commands:
Run 'gif chop COMMAND --help' for more information on a command.
```

### text

![before](doc/gunther.jpg)![after](doc/gunther.gif)
> woke | text | fried
```text
Usage: gif text [OPTIONS] [TEXT]
🅰️乁(˵ ͡☉ ͜ʖ ͡☉˵)┌🅱️
Arguments:
TEXT (default "#yeetgif")
Options:
-a, --background-alpha (default 0.7)
-s, --font-size (default 18.5)
-y, --text-y (default 0.3)
-p, --background-padding (default 3)
```

### nop

```text
Expand Down Expand Up @@ -432,3 +455,4 @@ Run 'gif meta COMMAND --help' for more information on a command.

- [Modified copy](pkg/imaging) of `github.com/disintegration/imaging`: [MIT License](pkg/imaging/LICENSE)
- `yeetgif` itself: [MIT License](LICENSE)
- [Roboto Regular TrueType Font](pkg/gifstatic/roboto.go): [Apache License 2.0](pkg/gifstatic/roboto.go-LICENSE)
11 changes: 11 additions & 0 deletions README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Composable GIF effects CLI, with reasonable defaults. Made for custom Slack/Disc
- [crowd](#crowd)
- [erase](#erase)
- [chop](#chop)
- [text](#text)
- [nop](#nop)
- [meta](#meta)
- [Licensing](#licensing)
Expand Down Expand Up @@ -194,6 +195,15 @@ ${USAGE_erase}
${USAGE_chop}
```

### text

![before](doc/gunther.jpg)![after](doc/gunther.gif)
> woke | text | fried
```text
${USAGE_text}
```

### nop

```text
Expand Down Expand Up @@ -221,3 +231,4 @@ ${USAGE_meta}

- [Modified copy](pkg/imaging) of `github.com/disintegration/imaging`: [MIT License](pkg/imaging/LICENSE)
- `yeetgif` itself: [MIT License](LICENSE)
- [Roboto Regular TrueType Font](pkg/gifstatic/roboto.go): [Apache License 2.0](pkg/gifstatic/roboto.go-LICENSE)
2 changes: 2 additions & 0 deletions cmd/gif/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
commandCompose = "compose"
commandCrowd = "crowd"
commandChop = "chop"
commandText = "text"
commandMeta = "meta"
commandErase = "erase"
commandNop = "nop"
Expand Down Expand Up @@ -114,6 +115,7 @@ func init() {
app.Command(commandCrowd, "(⟃ ͜ʖ ⟄) ͜ʖ ͡°)( ° ͜ʖ( ° ͜ʖ °)", CommandCrowd)
app.Command(commandErase, "( ͡° ͜ʖ ͡°)=ε/̵͇̿̿/'̿̿ ̿ ̿ ̿ ̿ ̿", CommandErase)
app.Command(commandChop, "✂️( ͡°Ĺ̯ ͡° )🔪", CommandChop)
app.Command(commandText, "🅰️乁(˵ ͡☉ ͜ʖ ͡☉˵)┌🅱️", CommandText)
app.Command(commandNop, "乁(ᴗ ͜ʖ ᴗ)ㄏ", func(cmd *cli.Cmd) { cmd.Action = func() {} })
app.Command(commandMeta, "(🧠 ͡ಠ ʖ̯ ͡ಠ)┌", CommandMeta)
}
Expand Down
61 changes: 61 additions & 0 deletions cmd/gif/text.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"image"
"image/color"
"sync"

"github.com/sgreben/yeetgif/pkg/gifstatic"

"github.com/fogleman/gg"
"github.com/golang/freetype/truetype"

cli "github.com/jawher/mow.cli"
"github.com/sgreben/yeetgif/pkg/gifcmd"
"github.com/sgreben/yeetgif/pkg/imaging"
)

var (
font, _ = truetype.Parse(gifstatic.RobotoTTF)
)

func CommandText(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS] [TEXT]"
var (
a = gifcmd.Float{Value: 0.7}
s = gifcmd.Float{Value: 18.5}
y = gifcmd.Float{Value: 0.30}
padY = gifcmd.Float{Value: 3}
)
cmd.VarOpt("a background-alpha", &a, "")
cmd.VarOpt("s font-size", &s, "")
cmd.VarOpt("y text-y", &y, "")
cmd.VarOpt("p background-padding", &padY, "")
text := cmd.StringArg("TEXT", "#yeetgif", "")
cmd.Action = func() {
Text(images, a.Value, padY.Value, s.Value, y.Value, *text)
}
}

func Text(images []image.Image, alpha, padY, sizePoints, textYFactor float64, text string) {
fontFace := truetype.NewFace(font, &truetype.Options{Size: sizePoints})
var fontMutex sync.Mutex
padYBottomExtra := 6.0
write := func(i int) {
w, h := images[i].Bounds().Dx(), images[i].Bounds().Dy()
ctx := gg.NewContext(w, h)
ctx.SetFontFace(fontFace)
ctx.SetColor(color.White)
fontMutex.Lock()
_, textHeight := ctx.MeasureString(text)
textY := float64(h) * (1 - textYFactor)
ctx.DrawStringAnchored(text, float64(w)/2, textY, 0.5, 0.5)
fontMutex.Unlock()
textBackgroundHeight := textHeight + 2*padY + padYBottomExtra
textBackgroundY := textY - (textBackgroundHeight-padYBottomExtra)/2
textBackground := imaging.New(w, int(textBackgroundHeight), color.Black)
images[i] = imaging.Overlay(images[i], textBackground, image.Point{Y: int(textBackgroundY)}, alpha)
images[i] = imaging.Overlay(images[i], ctx.Image(), image.ZP, 1.0)
}
parallel(len(images), write)
}
Binary file added doc/gunther.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/gunther.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions pkg/gifstatic/roboto.go

Large diffs are not rendered by default.

Loading

0 comments on commit 7447b20

Please sign in to comment.