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


Golang GIF.LoopCount方法代碼示例

本文整理匯總了Golang中image/gif.GIF.LoopCount方法的典型用法代碼示例。如果您正苦於以下問題:Golang GIF.LoopCount方法的具體用法?Golang GIF.LoopCount怎麽用?Golang GIF.LoopCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在image/gif.GIF的用法示例。


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

示例1: MakeGif

func (bam *BAM) MakeGif(outputPath string, name string) error {
	for idx, seq := range bam.Sequences {
		if seq.Start >= 0 && seq.Count > 0 {
			pathname := filepath.Join(outputPath, fmt.Sprintf("%s_%03d.gif", name, idx))
			g := gif.GIF{}
			g.Image = make([]*image.Paletted, seq.Count)
			g.Delay = make([]int, seq.Count)
			g.LoopCount = 0

			for iIdx := seq.Start; iIdx < seq.Start+seq.Count; iIdx++ {
				imgIdx := int(bam.SequenceToImage[iIdx])

				g.Image[iIdx-seq.Start] = &bam.Image[imgIdx]
				g.Delay[iIdx-seq.Start] = 10
			}
			outFile, err := os.Create(pathname)
			if err != nil {
				return fmt.Errorf("Unable to create file %s: %v", pathname, err)
			}
			gif.EncodeAll(outFile, &g)

			outFile.Close()
		}
	}
	return nil
}
開發者ID:MasterScrat,項目名稱:bgfileformats,代碼行數:26,代碼來源:bam.go

示例2: Process

// Process implements Processor.
func (prc *SimpleProcessor) Process(g *gif.GIF, params imageserver.Params) (*gif.GIF, error) {
	out := new(gif.GIF)
	var err error
	out.Image, err = prc.processImages(g.Image, params)
	if err != nil {
		return nil, err
	}
	out.Delay = make([]int, len(g.Delay))
	copy(out.Delay, g.Delay)
	out.LoopCount = g.LoopCount
	if g.Disposal != nil {
		out.Disposal = make([]byte, len(g.Disposal))
		copy(out.Disposal, g.Disposal)
	}
	out.Config.ColorModel = g.Config.ColorModel
	for _, p := range out.Image {
		if p.Rect.Max.X > out.Config.Width {
			out.Config.Width = p.Rect.Max.X
		}
		if p.Rect.Max.Y > out.Config.Height {
			out.Config.Height = p.Rect.Max.Y
		}
	}
	out.BackgroundIndex = g.BackgroundIndex
	return out, nil
}
開發者ID:cautio,項目名稱:imageserver,代碼行數:27,代碼來源:processor.go

示例3: main

func main() {
	args := os.Args[1:]

	if len(args) > 2 || len(args) == 0 {
		showUsage()
		return
	}

	input := args[0]

	fmt.Println("Reading file", input)
	file, err := os.Open(input)
	if err != nil {
		fmt.Println(err)
		return
	}

	img, err := gif.DecodeAll(file)

	if err != nil {
		fmt.Println(err)
		return
	}

	reversed := new(gif.GIF)

	reversed.Delay = img.Delay
	reversed.LoopCount = img.LoopCount
	reversed.Image = reverse(img.Image)

	fmt.Println("Reversing..")

	var output string

	if len(args) == 2 {
		output = strings.TrimSuffix(args[1], filepath.Ext(input)) + ".gif"
	} else {
		output = strings.TrimSuffix(input, filepath.Ext(input)) + "_reversed.gif"
	}

	result, err := os.Create(output)

	if err != nil {
		fmt.Println(err)
		return
	}

	gif.EncodeAll(result, reversed)

	fmt.Println("✓ Saved", output)
}
開發者ID:akhilcacharya,項目名稱:gifreverse,代碼行數:51,代碼來源:gifreverse.go

示例4: Generate

// Generate writes to outFile an animated GIF
func (g *GifGenerator) Generate(input string, output string) (err error) {
	// virtual terminal
	var state = terminal.State{}
	vt, err := terminal.Create(&state, ioutil.NopCloser(bytes.NewBuffer([]byte{})))
	if err != nil {
		return
	}
	defer vt.Close()
	vt.Resize(g.Col, g.Row)

	// play and capture
	var (
		images []*image.Paletted
		delays []int
	)
	err = g.TtyPlay(input, vt, func(diff int32) (err error) {
		delay := int(float64(diff)/g.Speed) / 10000
		if delay > 0 {
			var img *image.Paletted
			img, err = g.Capture(&state)
			if err != nil {
				return
			}
			images = append(images, img)
			delays = append(delays, delay)
		}
		return nil
	})
	if err != nil {
		return
	}

	// generate gif file
	outFile, err := os.Create(output)
	if err != nil {
		return
	}
	defer outFile.Close()
	opts := gif.GIF{
		Image: images,
		Delay: delays,
	}
	if g.NoLoop {
		opts.LoopCount = 1
	}
	err = gif.EncodeAll(outFile, &opts)
	if err != nil {
		return
	}
	return nil
}
開發者ID:lengshuiyulangcn,項目名稱:ttyrec2gif,代碼行數:52,代碼來源:generator.go

示例5: main

func main() {
	dir, _ := ioutil.ReadDir(".")

	var imgs []*image.Paletted
	for _, file := range dir {
		f, _ := os.Open(file.Name())
		defer f.Close()

		if ext := path.Ext(file.Name()); ext != ".jpg" && ext != ".JPG" && ext != ".jpeg" && ext != ".png" {
			fmt.Printf("File not an image: %s\n", file.Name())
		} else {
			img, err := rs.ResizePixels(f, 400, 400)
			if err != nil {
				fmt.Println(err)
			}

			var opt gif.Options
			opt.NumColors = 256

			buf := new(bytes.Buffer)
			gif.Encode(buf, img, &opt)

			g, _ := gif.DecodeAll(buf)
			imgs = append(imgs, g.Image[0])
		}
	}

	g := new(gif.GIF)

	g.Image = imgs
	g.Delay = evenDelay(100, len(g.Image))
	g.LoopCount = 1000

	var opt gif.Options
	opt.NumColors = 256

	out, err := os.Create("./output.gif")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	err = gif.EncodeAll(out, g)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("Generated image to output.gif \n")
}
開發者ID:brydavis,項目名稱:maxgif,代碼行數:49,代碼來源:encode.go

示例6: main

func main() {

	out, err := os.Create("./output.gif")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	dir, _ := ioutil.ReadDir(".")

	var imgs []*image.Paletted

	for _, file := range dir {
		switch ext := path.Ext(file.Name()); ext {
		case ".jpg":

			f, _ := os.Open(file.Name())
			img, _ := jpeg.Decode(f)
			var opt gif.Options
			opt.NumColors = 256

			buf := new(bytes.Buffer)
			gif.Encode(buf, img, &opt)

			g, _ := gif.DecodeAll(buf)

			imgs = append(imgs, g.Image[0])

		default:
			fmt.Println(ext)
		}
	}

	g := new(gif.GIF)

	g.Image = imgs

	var opt gif.Options
	opt.NumColors = 256
	g.Delay = []int{100, 100, 100}
	g.LoopCount = 1000

	err = gif.EncodeAll(out, g)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("Generated image to output.gif \n")
}
開發者ID:brydavis,項目名稱:gum,代碼行數:49,代碼來源:encode.go

示例7: EncodeAll

// EncodeAll writes the images in g to w in GIF format with the
// given loop count and delay between frames.
func EncodeAll(w io.Writer, g *gif.GIF) error {
	if len(g.Image) == 0 {
		return errors.New("gif: must provide at least one image")
	}

	if len(g.Image) != len(g.Delay) {
		return errors.New("gif: mismatched image and delay lengths")
	}
	if g.LoopCount < 0 {
		g.LoopCount = 0
	}

	e := newEncoder(w)
	e.g = g
	e.writeHeader()
	for i, pm := range g.Image {
		e.writeImageBlock(pm, g.Delay[i])
	}
	e.writeByte(sTrailer)
	e.flush()
	return e.err
}
開發者ID:qmdx,項目名稱:gogif,代碼行數:24,代碼來源:writer.go

示例8: EncodeAll

// EncodeAll encodes a gif to an io.Writer.
func EncodeAll(w io.Writer, g *gif.GIF) (err error) {
	if len(g.Image) == 0 {
		return errors.New("Can't encode zero images.")
	}

	if len(g.Image) != len(g.Delay) {
		return errors.New(fmt.Sprintf("Number of images and delays must be equal (%s x %s)", len(g.Image), len(g.Delay)))
	}

	if g.LoopCount < 0 {
		g.LoopCount = 0
	}

	var e encoder
	e.w = w
	e.g = g

	err = e.writeHeader()
	if err != nil {
		return
	}

	for i, _ := range e.g.Image {
		err = e.writeFrame(i)
		if err != nil {
			return
		}
	}

	_, err = w.Write([]byte{';'})
	if err != nil {
		return
	}

	return nil
}
開發者ID:boppreh,項目名稱:gifencoder,代碼行數:37,代碼來源:gifencoder.go

示例9: Generate

// Generate writes to outFile an animated GIF
func (g *GifGenerator) Generate(inFile string, outFile string) (err error) {
	tempDir, err := ioutil.TempDir("", "ttygif")
	if err != nil {
		return
	}
	defer os.RemoveAll(tempDir)

	var (
		delays    []int
		timestamp ttyread.TimeVal
	)
	worker := NewWorker()
	// play and capture
	err = Play(inFile, func(diff ttyread.TimeVal) (err error) {
		delay := int(float64(diff.Sec*1000000+diff.Usec)/g.Speed) / 10000
		if delay == 0 {
			return nil
		}
		delays = append(delays, delay)
		timestamp = timestamp.Add(diff)

		// capture and append to images
		imgPath := filepath.Join(tempDir, fmt.Sprintf("%03d_%06d", timestamp.Sec, timestamp.Usec))
		fileType, err := CaptureImage(imgPath)
		if err != nil {
			return
		}
		worker.AddTargetFile(imgPath, fileType)
		return nil
	})
	if err != nil {
		return
	}
	// get paletted images from capture files
	progress := make(chan struct{})
	go func() {
	Loop:
		for {
			select {
			case <-time.Tick(time.Millisecond * 500):
				print(".")
			case <-progress:
				break Loop
			}
		}
		print("\r")
	}()
	images, err := worker.GetAllImages()
	if err != nil {
		return
	}
	close(progress)

	// generate GIF file
	file, err := os.Create(outFile)
	if err != nil {
		return
	}
	defer file.Close()
	opts := gif.GIF{
		Image: images,
		Delay: delays,
	}
	if g.NoLoop {
		opts.LoopCount = 1
	}
	err = gif.EncodeAll(file, &opts)
	if err != nil {
		return
	}
	return nil
}
開發者ID:charpty,項目名稱:ttygif,代碼行數:73,代碼來源:generator.go


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