-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
version: 2 | ||
jobs: | ||
test: | ||
docker: | ||
- image: circleci/golang:1.12 | ||
environment: | ||
GO111MODULE: "on" | ||
steps: | ||
- checkout | ||
- run: | ||
name: Build | ||
command: | | ||
set -x | ||
go build -o gif-progress main/main.go | ||
./gif-progress --help | ||
build: | ||
docker: | ||
- image: circleci/golang:1.12 | ||
environment: | ||
GO111MODULE: "on" | ||
DIST: "/go/dist" | ||
steps: | ||
- checkout | ||
- run: | ||
name: Build | ||
command: | | ||
set -x | ||
mkdir $DIST | ||
# (from: https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04) | ||
platforms=("linux/amd64" "darwin/amd64" "windows/amd64") | ||
for platform in "${platforms[@]}" | ||
do | ||
platform_split=(${platform//\// }) | ||
export GOOS=${platform_split[0]} | ||
export GOARCH=${platform_split[1]} | ||
BUILD_PATH=gif-progress-$GOOS-$GOARCH | ||
mkdir $BUILD_PATH | ||
# Build | ||
go build -o $BUILD_PATH/gif-progress main/main.go | ||
# Create .zip | ||
zip -r $DIST/$BUILD_PATH.zip $BUILD_PATH | ||
# Create .tar.gz | ||
tar zcvf $DIST/$BUILD_PATH.tar.gz $BUILD_PATH | ||
done | ||
- persist_to_workspace: | ||
root: /go/dist | ||
paths: | ||
- . | ||
|
||
github_release: | ||
docker: | ||
- image: cibuilds/github:0.10 | ||
steps: | ||
- attach_workspace: | ||
at: /go/dist | ||
- run: | ||
name: Publish Release on GitHub | ||
command: | | ||
VERSION=$CIRCLE_TAG | ||
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} /go/dist | ||
workflows: | ||
version: 2 | ||
build: | ||
jobs: | ||
- test : | ||
filters: | ||
tags: | ||
only: /.*/ | ||
- build : | ||
filters: | ||
tags: | ||
only: /.*/ | ||
- github_release: | ||
requires: | ||
- test | ||
- build | ||
filters: | ||
tags: | ||
only: /.+/ | ||
branches: | ||
ignore: /.*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Ryo Ota | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# gif-progress | ||
[![CircleCI](https://circleci.com/gh/nwtgck/gif-progress.svg?style=shield)](https://circleci.com/gh/nwtgck/gif-progress) | ||
|
||
Attach progress bar to animated GIF | ||
|
||
![Ray Tracing](doc_assets/ray_tracing.gif) | ||
The original gif is from <https://github.com/nwtgck/ray-tracing-iow-rust>. | ||
|
||
## Installation | ||
Download binaries from [GitHub Release](https://github.com/nwtgck/gif-progress/releases). | ||
|
||
## Usage | ||
|
||
Generate a gif with bar. | ||
```bash | ||
cat in.gif | gif-progress > out.gif | ||
``` | ||
|
||
## Help | ||
|
||
```txt | ||
Attach progress bar to animated GIF | ||
Usage: | ||
gif-progress [flags] | ||
Flags: | ||
--bar-color string Bar color (default "#ccc") | ||
--bar-height int Bar height (default 5) | ||
--bar-top Bar is on top | ||
-h, --help help for gif-progress | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
gif_progress "github.com/nwtgck/gif-progress" | ||
"github.com/spf13/cobra" | ||
"gopkg.in/go-playground/colors.v1" | ||
"image/color" | ||
"image/gif" | ||
"os" | ||
) | ||
|
||
var barTop bool | ||
var barHeight int | ||
var barColorString string | ||
|
||
|
||
func init() { | ||
cobra.OnInitialize() | ||
RootCmd.Flags().BoolVar(&barTop, "bar-top", false, "Bar is on top") | ||
RootCmd.Flags().IntVar(&barHeight, "bar-height", 5, "Bar height") | ||
RootCmd.Flags().StringVar(&barColorString, "bar-color", "#ccc", "Bar color") | ||
} | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: os.Args[0], | ||
Short: "gif-progress", | ||
Long: "Attach progress bar to animated GIF", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// Parse color | ||
hex, err := colors.ParseHEX(barColorString) | ||
if err != nil { | ||
return err | ||
} | ||
c := hex.ToRGB() | ||
barColor := color.RGBA{c.R, c.G, c.B, 255} | ||
// TODO: Hard code stdin | ||
inOutGif, err := gif.DecodeAll(os.Stdin) | ||
if err != nil { | ||
return err | ||
} | ||
// Add progress bar to gif | ||
gif_progress.AddProgressBar(inOutGif, barTop, barHeight, barColor) | ||
// Write gif | ||
// TODO: Hard code stdout | ||
err = gif.EncodeAll(os.Stdout, inOutGif) | ||
return err | ||
}, | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package gif_progress | ||
|
||
import ( | ||
"image/color" | ||
"image/gif" | ||
) | ||
|
||
func AddProgressBar(inOutGif *gif.GIF, barTop bool, barHeight int, barColor color.RGBA) { | ||
// NOTE: inOutGif is changed destructively | ||
width := inOutGif.Config.Width | ||
height := inOutGif.Config.Height | ||
image_len := len(inOutGif.Image) | ||
for i, paletted := range inOutGif.Image { | ||
w := int(float32(width) * ((float32(i)+1)/float32(image_len))) | ||
for x := 0; x < w; x++ { | ||
for h := 0; h < barHeight; h++ { | ||
var y = h | ||
if !barTop { | ||
y = height - h | ||
} | ||
paletted.Set(x, y, barColor) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/nwtgck/gif-progress | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/spf13/cobra v0.0.5 | ||
gopkg.in/go-playground/colors.v1 v1.2.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= | ||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= | ||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= | ||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= | ||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= | ||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= | ||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= | ||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= | ||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= | ||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= | ||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= | ||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= | ||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= | ||
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= | ||
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= | ||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= | ||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= | ||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= | ||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= | ||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= | ||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= | ||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/go-playground/colors.v1 v1.2.0 h1:SPweMUve+ywPrfwao+UvfD5Ah78aOLUkT5RlJiZn52c= | ||
gopkg.in/go-playground/colors.v1 v1.2.0/go.mod h1:AvbqcMpNXVl5gBrM20jBm3VjjKBbH/kI5UnqjU7lxFI= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/nwtgck/gif-progress/cmd" | ||
"os" | ||
) | ||
|
||
func main () { | ||
if err := cmd.RootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(-1) | ||
} | ||
} |