Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
takkanm committed Sep 7, 2014
0 parents commit 609d59b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
furueru
17 changes: 17 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# furueru.go

## description

create shake gif from png file

## build

```
go build
```

## usage

```
$ ./furueru sample.png # > outfile sample.png.gif
```
68 changes: 68 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"os"
"image"
"image/gif"
"image/png"
"image/color/palette"
"math/rand"
)

func writeGifFile(outFileNmae string, g gif.GIF) {
outFile, _ := os.Create(outFileNmae)
defer outFile.Close()


g.Delay = make([]int, len(g.Image))
g.LoopCount = 0

gif.EncodeAll(outFile, &g)
}

func slideImage (in image.Image, slideX int, slideY int) *image.Paletted {
margin := 2
inBounds := in.Bounds()
rect := image.Rect(inBounds.Min.X, inBounds.Min.Y, inBounds.Max.X + margin, inBounds.Max.Y + margin)
pl := image.NewPaletted(rect, palette.WebSafe)

for x := 0; x < inBounds.Max.X; x++ {
for y := 0; y < inBounds.Max.Y; y++ {
pl.Set(x + slideX, y + slideY, in.At(x, y))
}
}
return pl
}

func calsSlideVolume() (int, int) {
x := (rand.Int() % 3)
y := (rand.Int() % 3)
return x, y
}

func generateAnimeGif(inFileNmae string) {
inFile, _ := os.Open(inFileNmae)
defer inFile.Close()

pngImage, _ := png.Decode(inFile)
moveTimes := 100

outGif := gif.GIF {
Image: []*image.Paletted {},
}

for s := 0; s < moveTimes; s++ {
palet := slideImage(pngImage, 1, 1)
outGif.Image = append(outGif.Image, palet)

slideX, slideY := calsSlideVolume()
palet = slideImage(pngImage, slideX, slideY)
outGif.Image = append(outGif.Image, palet)
}

writeGifFile(inFileNmae + ".gif", outGif)
}

func main () {
generateAnimeGif(os.Args[1])
}
Binary file added sample.png
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 sample.png.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 609d59b

Please sign in to comment.