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


Golang imaging.Open函數代碼示例

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


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

示例1: main

func main() {
	fmt.Println("ImgNet loading...")
	netSize := []int{3, 3}
	net := NewImgNet(netSize[0], netSize[1])

	imgOrig, err := imaging.Open("lena-colour.png")
	if err != nil {
		panic(err)
	}

	imgFiltered, err := imaging.Open("lena-colourdiff.png")
	if err != nil {
		panic(err)
	}

	targetImg, err := imaging.Open("lena-colour.png")
	if err != nil {
		panic(err)
	}

	fmt.Println("Teaching network.")
	for randcount := 0; randcount < 1000000; randcount++ {
		x := rand.Intn(imgOrig.Bounds().Dx()-netSize[0]) - netSize[0]/2
		y := rand.Intn(imgOrig.Bounds().Dy()-netSize[1]) - netSize[1]/2
		net.FF(image.Pt(x, y), &imgOrig)
		net.BP(image.Pt(x, y), &imgFiltered)
	}

	fmt.Println("Filtering image.")
	result := net.Filter(targetImg)
	imaging.Save(result, "output.png")

}
開發者ID:avesanen,項目名稱:neuro,代碼行數:33,代碼來源:main.go

示例2: openImageWhenReady

func openImageWhenReady(file string) (image.Image, error) {
	// Retry opening the image until err != image.ErrFormat
	// or the next retry would take over a minute.
	// FIXME

	var img image.Image
	var err error
	var retry int
	var t time.Duration

	for {
		t = time.Duration(1000 * (retry * 2))
		time.Sleep(time.Millisecond * t)

		img, err = imaging.Open(file)
		if err == image.ErrFormat {
			retry = retry + 1
			if retry*2 > 60 {
				break
			}
			continue
		}
		break
	}
	return img, err
}
開發者ID:ComSecNinja,項目名稱:manikyr,代碼行數:26,代碼來源:utils.go

示例3: ProcessAvatar

func ProcessAvatar(user *User) error {
	origImg, err := imaging.Open(GetAvatarPath(user, "o"))
	if err != nil {
		return err
	}

	src := imaging.Clone(origImg)

	for _, sz := range AvatarSizes {
		var dst image.Image

		switch sz.Type {
		case "thumbnail":
			dst = imaging.Thumbnail(src, sz.Width, sz.Height, imaging.Lanczos)
		case "fit":
			dst = imaging.Fit(src, sz.Width, sz.Height, imaging.Lanczos)
		}

		err := imaging.Save(dst, GetAvatarPath(user, sz.Suffix))
		if err != nil {
			return err
		}
	}

	return nil
}
開發者ID:postfix,項目名稱:quiet-1,代碼行數:26,代碼來源:processing.go

示例4: thumbFile

func thumbFile(filePath string) {
	src, _ := imaging.Open(filePath)
	var dst *image.NRGBA

	dst = imaging.Thumbnail(src, 48, 48, imaging.CatmullRom)
	imaging.Save(dst, filePath)
}
開發者ID:zeuson,項目名稱:gorevel,代碼行數:7,代碼來源:application.go

示例5: openImage

func openImage(fileName string) image.Image {
	img, err := imaging.Open(testDir + fileName)
	if err != nil {
		log.Fatalln(err)
	}
	return img
}
開發者ID:umahmood,項目名稱:perceptive,代碼行數:7,代碼來源:perceptive_test.go

示例6: editImage

func (p *program) editImage(rot Rot, folder string, list []string) error {
	for _, item := range list {
		filename := filepath.Join(config.FileRoot, folder, item)
		fi, err := os.Stat(filename)
		if err != nil {
			return err
		}
		fullImage, err := imaging.Open(filename)
		if err != nil {
			return err
		}

		switch rot {
		case RotLeft:
			fullImage = imaging.Rotate90(fullImage)
		case RotRight:
			fullImage = imaging.Rotate270(fullImage)
		case RotFlip:
			fullImage = imaging.Rotate180(fullImage)
		default:
			return fmt.Errorf("Unknown rot value: %d", rot)
		}
		err = imaging.Save(fullImage, filename)
		if err != nil {
			return err
		}
		tm := fi.ModTime()
		err = os.Chtimes(filename, tm, tm)
		if err != nil {
			return err
		}
	}
	return p.refreshCache(folder, list)
}
開發者ID:rdterner,項目名稱:photoview,代碼行數:34,代碼來源:editImage.go

示例7: ProcessPhoto

func ProcessPhoto(photo *Photo) error {
	origImg, err := imaging.Open(GetPhotoPath(photo, "o"))
	if err != nil {
		return err
	}

	src := imaging.Clone(origImg)

	for _, sz := range PhotoSizes {
		var dst image.Image

		switch sz.Type {
		case "thumbnail":
			dst = imaging.Thumbnail(src, sz.Width, sz.Height, imaging.Lanczos)
		case "fit":
			dst = imaging.Fit(src, sz.Width, sz.Height, imaging.Lanczos)
		}

		err := imaging.Save(dst, GetPhotoPath(photo, sz.Suffix))
		if err != nil {
			return err
		}
	}

	return nil
}
開發者ID:postfix,項目名稱:quiet-1,代碼行數:26,代碼來源:processing.go

示例8: go_get_image

func (ths *ImageTagServer) go_get_image(w http.ResponseWriter, r *http.Request) {
	path := r.URL.Query().Get("path")
	path = ths.imgRoot + path
	path = strings.Replace(path, "..", "", -1)

	info, infoErr := os.Stat(path)
	if infoErr != nil {
		http.Error(w, infoErr.Error(), http.StatusInternalServerError)
		return
	}

	if info.IsDir() == true {
		http.Error(w, "No an image", http.StatusBadRequest)
		return
	}

	img, err := imaging.Open(path)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Add("Content-Type", "image/jpeg")
	err = imaging.Encode(w, img, imaging.JPEG)
	if err != nil {
		http.Error(w, "Failed to thumbNail image", http.StatusInternalServerError)
		return
	}

}
開發者ID:rasmuswz,項目名稱:imagetag,代碼行數:30,代碼來源:imagetagserver.go

示例9: MakeThumbnail

// 生成縮略圖
func MakeThumbnail(fromFile string, w, h int) (image *image.NRGBA, err error) {
	srcImage, err := imaging.Open(fromFile)
	if err != nil {
		return nil, err
	}

	image = imaging.Thumbnail(srcImage, w, h, imaging.Lanczos)
	return
}
開發者ID:netw0rm,項目名稱:reweb,代碼行數:10,代碼來源:utils.go

示例10: open

//打開圖片文件
func (this *Image) open(filename string) error {

	src, err := imaging.Open(filename)
	if err != nil {
		return err
	}
	this.filename = filepath.Base(filename)
	this.source = src
	return nil
}
開發者ID:jango2015,項目名稱:go-cms,代碼行數:11,代碼來源:image.go

示例11: resizeImage

func resizeImage(filename string, size int) string {
	resizedFile := filename + ".resized.png"
	img, err := imaging.Open(filename)
	if err != nil {
		panic(err)
	}
	dstimg := imaging.Resize(img, size, 0, imaging.Box)
	imaging.Save(dstimg, resizedFile)
	return resizedFile
}
開發者ID:Daio-io,項目名稱:pic-sizer,代碼行數:10,代碼來源:main.go

示例12: GenerateThumbnail

func (f *File) GenerateThumbnail() error {
	fpath := filepath.Join(f.TagDir, f.Filename)

	s, err := imaging.Open(fpath)
	if err != nil {
		return err
	}

	thumb := imaging.Fill(s, 75, 75, imaging.Center, imaging.NearestNeighbor)
	err = imaging.Save(thumb, f.ThumbnailPath())
	return err
}
開發者ID:jmcarbo,項目名稱:filebin,代碼行數:12,代碼來源:file.go

示例13: GenerateThumbnail

func (be *Backend) GenerateThumbnail(bin string, filename string, width int, height int, crop bool) error {
	f, err := be.GetFileMetaData(bin, filename)
	if err != nil {
		return err
	}

	if strings.Split(f.MIME, "/")[0] != "image" {
		return errors.New("Batch job skipped: " + filename + " is not an image")
	}

	fpath := filepath.Join(be.filedir, bin, filename)
	cachedir := filepath.Join(be.filedir, bin, ".cache")
	if !isDir(cachedir) {
		if err := os.Mkdir(cachedir, 0700); err != nil {
			return err
		}
	}
	dst := filepath.Join(cachedir, strconv.Itoa(width)+"x"+strconv.Itoa(height)+"-"+filename)

	// Optimize to skip thumbnail generation if the thumbnail file exists
	// and is newer than the file.
	fi, err := os.Lstat(dst)
	if err == nil {
		if f.CreatedAt.After(fi.ModTime()) {
			// File newer than thumbnail. Ok to generate.
		} else {
			// File older than thumbnail. No need to generate.
			return nil
		}
	}

	s, err := imaging.Open(fpath)
	if err != nil {
		return err
	}

	if crop {
		im := imaging.Fill(s, width, height, imaging.Center, imaging.Lanczos)
		err = imaging.Save(im, dst)
	} else {
		im := imaging.Resize(s, width, height, imaging.Lanczos)
		err = imaging.Save(im, dst)
	}

	f.Links = be.GenerateLinks(f.Bin, f.Filename)
	be.Lock()
	defer be.Unlock()
	id := bin + filename
	delete(be.files, id)
	be.files[id] = f

	return err
}
開發者ID:espebra,項目名稱:filebin,代碼行數:53,代碼來源:fs.go

示例14: main

func main() {
	flag.Parse()

	if len(*destination) > 0 {
		err := os.MkdirAll(*destination, os.ModePerm)
		if err != nil {
			fmt.Printf("Unable to create destination: %s\n", err)
			os.Exit(1)
		}
	}

	extMatch := regexp.MustCompile(`\.[a-zA-Z0-9]+$`)

	filelist := flag.Args()
	// if len(filelist) == 0 {
	// 	filelist = []string{"./*.*"}
	// }

	for _, srcArg := range filelist {
		srcFilenames, err := filepath.Glob(srcArg)
		if err != nil {
			log.Printf("Glob error: %s\n", err)
			continue
		}
		for _, srcFilename := range srcFilenames {
			fmt.Printf("Processing [%s]... ", srcFilename)
			src, err := imaging.Open(srcFilename)
			if err != nil {
				log.Printf("error: %s\n", err)
				continue
			}
			dest := imaging.Grayscale(src)
			extension := *output
			if extension == "" {
				extension = strings.TrimLeft(filepath.Ext(srcFilename), ".")
			}
			destFilename := extMatch.ReplaceAllString(srcFilename, "") + fmt.Sprintf("-grayscale.%s", extension)
			if len(*destination) > 0 {
				_, file := filepath.Split(destFilename)
				destFilename = filepath.Join(*destination, file)
			}
			err = imaging.Save(dest, destFilename)
			if err != nil {
				log.Printf("error: %s\n", err)
				continue
			}
			fmt.Printf("OK; written to %s\n", destFilename)
		}
	}
}
開發者ID:scjalliance,項目名稱:grayscale,代碼行數:50,代碼來源:grayscale.go

示例15: thumbs

func thumbs(args []string, thumbSizes []int) {
	if newThumbsSizes != "" {
		vals := strings.Split(newThumbsSizes, ",")
		thumbSizes = make([]int, len(vals))
		for i := 0; i < len(vals); i++ {
			numstr := strings.TrimSpace(vals[i])
			if numstr == "" {
				thumbSizes[i] = 0
				continue
			}
			num, err := strconv.Atoi(numstr)
			if err != nil {
				log.Print(err)
				continue
			}
			thumbSizes[i] = num
		}
	}

	for i := 0; i < len(args); i++ {

		file := args[i]
		ext := filepath.Ext(file)

		_, err := os.Stat(file)
		if err != nil {
			log.Fatal("file " + file + " is not accessible")
		}

		img, err := imaging.Open(file)
		if err != nil {
			log.Fatal(err)
		}

		for j := 0; j < len(thumbSizes); j++ {
			if thumbSizes[j] == 0 {
				continue
			}
			resized := imaging.Resize(img, thumbSizes[j], 0, imaging.Lanczos)
			rect := resized.Bounds().Max
			out := fmt.Sprintf("%s_%dx%d%s",
				strings.TrimSuffix(file, ext), rect.X, rect.Y, ext)
			err = imaging.Save(resized, out)
			log.Println("saved " + out)
			if err != nil {
				log.Fatal(err)
			}
		}
	}
}
開發者ID:chairraver,項目名稱:img4hugo,代碼行數:50,代碼來源:img4hugo.go


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