當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gif.EncodeAll函數代碼示例

本文整理匯總了Golang中image/gif.EncodeAll函數的典型用法代碼示例。如果您正苦於以下問題:Golang EncodeAll函數的具體用法?Golang EncodeAll怎麽用?Golang EncodeAll使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了EncodeAll函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewLgtm

func NewLgtm(file *multipart.File, header *multipart.FileHeader) (*Lgtm, error) {
	input, err := gif.DecodeAll(*file)
	if err != nil {
		return nil, err
	}

	output, err := yosage.Generate(input)
	if err != nil {
		return nil, err
	}

	var b bytes.Buffer
	writer := bufio.NewWriter(&b)

	err = gif.EncodeAll(writer, output)
	if err != nil {
		return nil, err
	}
	writer.Flush()

	re := regexp.MustCompile(`\.(gif|GIF)$`)
	return &Lgtm{
		Filename: re.ReplaceAllString(header.Filename, "") + "_lgtm.gif",
		Data:     base64.StdEncoding.EncodeToString(b.Bytes()),
	}, nil
}
開發者ID:hico-horiuchi,項目名稱:yosage-web,代碼行數:26,代碼來源:lgtm.go

示例2: lissajous

func lissajous(out io.Writer) {
	const (
		cycles  = 5     // number of complete x oscillator revolutions
		res     = 0.001 // angular resolution
		size    = 100   // image canvas covers [-size..+size]
		nframes = 64    // number of animation frames
		delay   = 8     // delay between frames in 10ms units
	)
	freq := rand.Float64() * 3.0 // relative frequency of y oscillator
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0 // phase difference
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		index := uint8(rand.Int() % len(palette)) // random palette index color
		if index == 0 {
			index = 1 // change the index if the color is the same as the background color
		}
		for t := 0.0; t < cycles*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), index)
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	if err := gif.EncodeAll(out, &anim); err != nil {
		log.Fatal(err)
	}
}
開發者ID:xaviergustavo,項目名稱:go-book,代碼行數:31,代碼來源:lissajous.go

示例3: lissajous

func lissajous(out http.ResponseWriter, r *http.Request) {
	const (
		cycles  = 5
		res     = 0.001
		size    = 100
		nframes = 64
		delay   = 8
	)

	freq := rand.Float64() * 3.0
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		for t := 0.0; t < cycles*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), blackIndex)
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}

	gif.EncodeAll(out, &anim)
}
開發者ID:oywc410,項目名稱:MYPG,代碼行數:27,代碼來源:7-02WEB計數器.go

示例4: Writter

// Writter writes a Gif
// @param out a Writter
// @param cycles number of complete x oscillator revolutions
func Writter(out io.Writer, cycles float64) {
	const (
		res     = 0.001 // angular resolution
		size    = 100   // image canvas covers [-size..+size]
		nframes = 64    // number of animation frames
		delay   = 8     // delay between frames in 10ms units
	)
	freq := rand.Float64() * 12.0 // relative frequency of y oscillator
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0 // phase difference
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, pallete)
		for t := 0.0; t < cycles*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			if i%2 == 0 {
				img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), greenIndex)
			} else {
				img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), blueIndex)
			}

		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	gif.EncodeAll(out, &anim)
}
開發者ID:flyinprogrammer,項目名稱:golangbluewhite,代碼行數:32,代碼來源:writter.go

示例5: FuzzAll

func FuzzAll(data []byte) int {
	cfg, err := gif.DecodeConfig(bytes.NewReader(data))
	if err != nil {
		return 0
	}
	if cfg.Width*cfg.Height > 1e6 {
		return 0
	}
	img, err := gif.DecodeAll(bytes.NewReader(data))
	if err != nil {
		return 0
	}
	w := new(bytes.Buffer)
	err = gif.EncodeAll(w, img)
	if err != nil {
		panic(err)
	}
	img1, err := gif.DecodeAll(w)
	if err != nil {
		panic(err)
	}
	if img.LoopCount == 0 && img1.LoopCount == -1 {
		// https://github.com/golang/go/issues/11287
		img1.LoopCount = 0
	}
	// https://github.com/golang/go/issues/11288
	img1.Disposal = img.Disposal
	if !fuzz.DeepEqual(img, img1) {
		fmt.Printf("gif0: %#v\n", img)
		fmt.Printf("gif1: %#v\n", img1)
		panic("gif changed")
	}
	return 1
}
開發者ID:rlmcpherson,項目名稱:go-fuzz,代碼行數:34,代碼來源:gif.go

示例6: lissajous

func lissajous(out http.ResponseWriter, r *http.Request) {
	const (
		res     = 0.001 // angular resolution
		size    = 500   // image canvas covers [-size..+size]
		nframes = 64    // number of animation frames
		delay   = 8     // delay between frames in 10ms units
	)
	if err := r.ParseForm(); err != nil {
		os.Exit(1)
	}
	for k, v := range r.Form {
		fmt.Printf("%s:%s\n", k, v)
	}
	cyclesInt, _ := strconv.Atoi(r.Form.Get("cycles")) // number of complete x oscillator revolutions
	cycles := float64(cyclesInt)
	fmt.Printf("Float is: %f\n", cycles)
	freq := rand.Float64() * 3.0 // relative frequency of y oscillator
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0 // phase difference
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		for t := 0.0; t < cycles*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5),
				blackIndex)
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	gif.EncodeAll(out, &anim) // NOTE: ignoring encoding errors
}
開發者ID:perryh,項目名稱:gopl.io,代碼行數:34,代碼來源:main.go

示例7: Process

// Process the GIF read from r, applying transform to each frame, and writing
// the result to w.
func Process(w io.Writer, r io.Reader, transform TransformFunc) error {
	if transform == nil {
		_, err := io.Copy(w, r)
		return err
	}

	// Decode the original gif.
	im, err := gif.DecodeAll(r)
	if err != nil {
		return err
	}

	// Create a new RGBA image to hold the incremental frames.
	firstFrame := im.Image[0].Bounds()
	b := image.Rect(0, 0, firstFrame.Dx(), firstFrame.Dy())
	img := image.NewRGBA(b)

	// Resize each frame.
	for index, frame := range im.Image {
		bounds := frame.Bounds()
		draw.Draw(img, bounds, frame, bounds.Min, draw.Over)
		im.Image[index] = imageToPaletted(transform(img), frame.Palette)
	}

	// Set image.Config to new height and width
	im.Config.Width = im.Image[0].Bounds().Max.X
	im.Config.Height = im.Image[0].Bounds().Max.Y

	return gif.EncodeAll(w, im)
}
開發者ID:immunda,項目名稱:imageproxy,代碼行數:32,代碼來源:gifresize.go

示例8: lissajous

func lissajous(write http.ResponseWriter, read *http.Request) {
	const (
		res     = 0.001 // angular resolution
		size    = 100   // image canvas covers [-size..+size]
		nframes = 64    // number of animation frames
		delay   = 8     // delay between frames in 10ms units
	)

	cycles, _ := strconv.Atoi(read.URL.Query()["cycles"][0])

	freq := rand.Float64() * 3.0 // relative frequency of y oscillator
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0 // phase difference
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		for t := 0.0; t < float64(cycles)*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5),
				blackIndex)
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	gif.EncodeAll(write, &anim) // NOTE: ignoring encoding errors
}
開發者ID:hktmy,項目名稱:Go_training,代碼行數:28,代碼來源:main.go

示例9: lissajous

func lissajous(out io.Writer, cycles int) {
	rand.Seed(time.Now().UTC().UnixNano())
	const (
		res     = 0.001
		size    = 100
		nframes = 64
		delay   = 8
	)
	freq := rand.Float64() * 3.0 // relative frequency of y oscillator
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0 // phase difference
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		for t := 0.0; t < float64(cycles)*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5),
				uint8(1+rand.Intn(4-1))) // randomly generated color
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	gif.EncodeAll(out, &anim) // NOTE: ignoring encoding errors
}
開發者ID:jackfrancis,項目名稱:donovan-kernighan,代碼行數:26,代碼來源:lissajous.go

示例10: lissajous

func lissajous(out io.Writer) {
	const (
		cycles  = 5
		res     = 0.001
		size    = 100
		nframes = 64
		delay   = 8
	)

	freq := rand.Float64() * 3.0
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0

	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		for t := 0.0; t < cycles*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), greenIndex)
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	err := gif.EncodeAll(out, &anim)

	if err != nil {
		panic("Gif encoding error")
	}
}
開發者ID:johnkelly,項目名稱:go_samples,代碼行數:31,代碼來源:main.go

示例11: mainDrawAnimation

func mainDrawAnimation() error {
	log.Printf("Drawing animation")

	iterations := 8
	imageWidth := 512.0

	g := gif.GIF{
		Image:     make([]*image.Paletted, iterations),
		Delay:     make([]int, iterations),
		LoopCount: 0,
	}

	for i := 0; i < iterations; i++ {
		log.Printf("    Drawing frame %d", i)

		n := 1 << uint(i+1)
		h := CreateHilbertImage(n, imageWidth/float64(n))
		h.DrawText = false
		img, err := h.Draw()
		if err != nil {
			return err
		}

		g.Image[i] = convertToPaletted(img) // draw2d doesn't support paletted images, so we convert
		g.Delay[i] = 200                    // 200 x 100th of a second = 2 second
	}

	f, err := os.Create("hilbert_animation.gif")
	if err != nil {
		return err
	}
	return gif.EncodeAll(f, &g)
}
開發者ID:dushmis,項目名稱:hilbert,代碼行數:33,代碼來源:demo.go

示例12: main

func main() {
	var images []*image.Paletted
	var delays []int
	f, _ := os.Create("foo.gif")
	rect := image.Rect(0, 0, 28+24*4, 20+18*10)
	// not a loop anymore
	m := image.NewPaletted(rect, pal)
	black := pal.Convert(color.RGBA{0, 0, 0, 255})
	draw.Draw(m, rect, &image.Uniform{black}, image.ZP, draw.Src)
	for i := 0; i < 10; i++ {
		for j := 0; j < 4; j++ {
			x := 10 + j*24
			y := 10 + i*18
			if i%2 == 1 {
				x += 12
			}
			drawHex(m, x, y, 20)
		}
	}
	images = append(images, m)
	delays = append(delays, 10)
	// end of not a loop anymore
	anim := gif.GIF{Image: images, Delay: delays, LoopCount: 1000}
	gif.EncodeAll(f, &anim)
}
開發者ID:prattmic,項目名稱:icfp2015,代碼行數:25,代碼來源:main.go

示例13: process_file

func process_file(filename string) error {
	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()

	reader := bufio.NewReader(f)
	g, err := gif.DecodeAll(reader)
	if err != nil {
		return err
	}
	err = debarf_image(g)

	of, err := os.Create("out.gif")
	if err != nil {
		return err
	}
	defer of.Close()
	writer := bufio.NewWriter(of)
	err = gif.EncodeAll(writer, g)
	if err != nil {
		return err
	}
	return err
}
開發者ID:nathan-b,項目名稱:gif-debarfer,代碼行數:26,代碼來源:debarfer.go

示例14: lissajous

func lissajous(out io.Writer, cycles int) {
	if cycles == 0 {
		cycles = 5
	}
	const (
		res     = 0.001
		size    = 100
		nframes = 64
		delay   = 8
	)
	freq := rand.Float64() * 3.0
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		color := rand.Intn(216)
		for t := 0.0; t < float64(cycles)*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), uint8(color))
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	gif.EncodeAll(out, &anim)
}
開發者ID:k4rtik,項目名稱:gopl,代碼行數:28,代碼來源:lissajous.go

示例15: lissajous

func lissajous(out io.Writer, config map[string]int) {
	cycles := 5   // number of complete x oscillator revolutions
	res := 0.001  // angular resolution
	size := 100   // image canvas covers [-size..+size]
	nframes := 63 // number of animation frames
	delay := 8    // delay between frames in 10ms units
	if v, ok := config["cycles"]; ok {
		cycles = v
	}
	if v, ok := config["size"]; ok {
		size = v
	}
	freq := rand.Float64() * 3.0 // relative frequency of y oscillator
	anim := gif.GIF{LoopCount: nframes}
	phase := 0.0 // phase difference
	for i := 0; i < nframes; i++ {
		rect := image.Rect(0, 0, 2*size+1, 2*size+1)
		img := image.NewPaletted(rect, palette)
		for t := 0.0; t < float64(cycles)*2*math.Pi; t += res {
			x := math.Sin(t)
			y := math.Sin(t*freq + phase)
			img.SetColorIndex(size+int(x*float64(size)+0.5), size+int(y*float64(size)+0.5),
				greenIndex)
		}
		phase += 0.1
		anim.Delay = append(anim.Delay, delay)
		anim.Image = append(anim.Image, img)
	}
	gif.EncodeAll(out, &anim) // NOTE: ignoring encoding errors
}
開發者ID:chris-gilmore,項目名稱:gopl,代碼行數:30,代碼來源:ex-1.12.go


注:本文中的image/gif.EncodeAll函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。