当前位置: 首页>>代码示例>>Golang>>正文


Golang exif.Decode函数代码示例

本文整理汇总了Golang中github.com/rwcarlsen/goexif/exif.Decode函数的典型用法代码示例。如果您正苦于以下问题:Golang Decode函数的具体用法?Golang Decode怎么用?Golang Decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: readOrientation

func readOrientation(r io.ReadSeeker) (int, error) {
	_, err := r.Seek(0, os.SEEK_SET)

	if err != nil {
		fmt.Println("Failed to seek to beginning of stream")
		return 0, err
	}

	x, err := exif.Decode(r)

	if err != nil {
		fmt.Println("Failed to decode EXIF", err)
		return 0, err
	}

	orientationData, err := x.Get(exif.Orientation)

	if err != nil {
		fmt.Println("Failed to read orientation property")
		return 0, err
	}

	orientation, err := orientationData.Int(0)

	if err != nil {
		fmt.Println("Failed to decode orientation")
		return 0, err
	}

	return orientation, nil
}
开发者ID:zqzca,项目名称:back,代码行数:31,代码来源:thumbnail.go

示例2: main

func main() {
	fi, err := ioutil.ReadDir("../../../images/")
	if err != nil {
		log.Fatal(err)
	}

	for _, v := range fi {

		f, err := os.Open(v.Name())
		if err != nil {
			log.Fatal(err)
		}

		x, err := exif.Decode(f)
		if err != nil {
			log.Fatal(err)
		}

		tm, _ := x.DateTime()
		fmt.Println("Taken: ", tm)

		lat, long, _ := x.LatLong()
		fmt.Println("lat, long: ", lat, ", ", long)
	}
}
开发者ID:ardan-bkennedy,项目名称:la,代码行数:25,代码来源:main.go

示例3: Load

// Load initializes a Photograph from a file.
func (p *Photograph) Load(fileName string) error {
	p.OriginalFileName = fileName
	fd, err := os.Open(fileName)
	if err != nil {
		logging.Log.Error("%v", err)
		return err
	}
	defer fd.Close()
	exif.RegisterParsers(mknote.All...)
	exifData, err := exif.Decode(fd)
	if err != nil {
		logging.Log.Error("%v", err)
		return err
	}
	err = exifData.Walk(p)
	if err != nil {
		logging.Log.Error("%v", err)
		return err
	}
	offset, err := fd.Seek(0, 0)
	if err != nil {
		logging.Log.Error("%v", err)
		return err
	}
	logging.Log.Debug("offset=%v", offset)
	p.Data, err = ioutil.ReadAll(fd)
	if err != nil {
		logging.Log.Error("%v", err)
		return err
	}

	return nil
}
开发者ID:hauva69,项目名称:photowalk,代码行数:34,代码来源:photograph.go

示例4: ReadRAF

// ReadRAF makes a new RAF from a file
func ReadRAF(fname string) *RAF {
	raf := new(RAF)

	f, err := os.Open(fname)
	defer f.Close()

	if err == nil {
		err = binary.Read(f, binary.BigEndian, &raf.Header)
	}

	jbuf := make([]byte, raf.Header.Dir.Jpeg.Len)
	f.ReadAt(jbuf, int64(raf.Header.Dir.Jpeg.IDX))
	raf.Jpeg = jbuf

	// Soon.
	// exif.RegisterParsers(mknote.Fuji)

	buf := bytes.NewBuffer(jbuf)
	raf.Exif, err = exif.Decode(buf)

	if err != nil {
		panic(err)
	}

	return raf
}
开发者ID:kladd,项目名称:raw,代码行数:27,代码来源:raw.go

示例5: getDateFromExif

func getDateFromExif(file string) (error, time.Time) {
	f, err := os.Open(file)
	defer f.Close()

	if err != nil {
		return errors.New("pclassify: warning: read exif info failed"), time.Now()
	}

	x, err := exif.Decode(f)
	if err != nil {
		return errors.New("pclassify: warning: read exif info failed"), time.Now()
	}

	ts, err := x.Get(exif.DateTimeOriginal)
	if err != nil {
		return errors.New("pclassify: warning: read exif info failed"), time.Now()
	}

	const layout = "2006:01:02 15:04:05"
	t, err := time.ParseInLocation(layout, ts.StringVal(), time.Local)
	if err != nil {
		return errors.New("pclassify: warning: read exif info failed"), time.Now()
	}

	return nil, t
}
开发者ID:viecks,项目名称:photoutils,代码行数:26,代码来源:pclassify.go

示例6: orient

func orient(r io.Reader, i image.Image) (image.Image, error) {
	t := log.Start()
	defer log.End(t)

	e, err := exif.Decode(r)
	if err != nil {
		log.Printf("fail to decode exif: %v", err)
		return nil, err
	}
	tag, err := e.Get(exif.Orientation)
	// Orientationタグが存在しない場合、処理を完了する
	if err != nil {
		log.Println("oritentation tag doesn't exist")
		return nil, err
	}
	o, err := tag.Int(0)
	if err != nil {
		log.Println("oritentation tag is't int")
		return nil, err
	}

	rect := i.Bounds()
	// orientation=5~8 なら画像サイズの縦横を入れ替える
	if o >= 5 && o <= 8 {
		rect = RotateRect(rect)
	}
	d := image.NewRGBA64(rect)
	a := affines[o]
	a.TransformCenter(d, i, interp.Bilinear)

	return d, nil
}
开发者ID:go-microservices,项目名称:resizer,代码行数:32,代码来源:processor.go

示例7: getDateTime

// getDateTime reads the exif data from fname and returns a string representation
// of the DateTimeOriginal tag.
// TODO move to its own package?
func getDateTime(fname string) (time.Time, error) {
	f, err := os.Open(fname)
	if err != nil {
		return time.Now(), err
	}
	defer f.Close()

	x, err := exif.Decode(f)
	if err != nil {
		return time.Now(), err
	}

	date, err := x.Get(exif.DateTimeOriginal)
	if err != nil {
		return time.Now(), err
	}
	dateStr, err := date.StringVal()
	if err != nil {
		return time.Now(), nil
	}
	log.Println("Setting DateTimeOriginal to ", dateStr, " on ", fname)
	t, err := time.Parse("2006:01:02 15:04:05", dateStr)
	if err != nil {
		return time.Now(), err
	}

	return t, nil
}
开发者ID:quincy,项目名称:photo_spool,代码行数:31,代码来源:spooler.go

示例8: main

func main() {
	ImageFileName := flag.String("image", "", "Dont use pngs please.")
	flag.Parse()
	var R io.Reader

	if len(*ImageFileName) > 0 {

		Rrr, err := os.Open(*ImageFileName)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", "Cant open file.")
		}
		R = Rrr
	}
	if len(*ImageFileName) == 0 {
		R = os.Stdin
	}

	ExifData, err := exif.Decode(R)
	if err == io.EOF {
		fmt.Fprintf(os.Stderr, "%s\n", "Error decoding file.")
	}
	if err != io.EOF {
		Location, err := goexifgps.DecodeGPS(ExifData)
		if err != io.EOF {
			fmt.Println(Location)
		}
		if err == io.EOF {
			fmt.Fprintf(os.Stderr, "%s\n", "Contains no GPS exif data.")
		}
	}

}
开发者ID:kurtcoke,项目名称:goexifgps,代码行数:32,代码来源:cmdtool.go

示例9: main

func main() {
	fname := "01.jpg"

	f, err := os.Open(fname)
	if err != nil {
		log.Fatal(err)
	}

	// Optionally register camera makenote data parsing - currently Nikon and
	// Canon are supported.
	exif.RegisterParsers(mknote.All...)

	x, err := exif.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	camModel, _ := x.Get(exif.Model) // normally, don't ignore errors!
	fmt.Println(camModel.StringVal())

	focal, _ := x.Get(exif.FocalLength)
	numer, denom, _ := focal.Rat2(0) // retrieve first (only) rat. value
	fmt.Printf("%v/%v", numer, denom)

	// Two convenience functions exist for date/time taken and GPS coords:
	tm, _ := x.DateTime()
	fmt.Println("Taken: ", tm)

	lat, long, _ := x.LatLong()
	fmt.Println("lat, long: ", lat, ", ", long)
}
开发者ID:RaviTezu,项目名称:GolangTraining,代码行数:31,代码来源:main.go

示例10: createPhoto

func createPhoto(sourceFilename string) (util.Photo, error) {
	photo := util.Photo{}

	f, err := os.Open(imageSourceFolderPath + sourceFilename)
	if err != nil {
		log.Println(err)
		return photo, err
	}

	x, err := exif.Decode(f)
	if err != nil {
		log.Println(sourceFilename, err)
		return photo, err
	}
	tm, _ := x.DateTime()
	if false {
		log.Println("Taken: ", tm)
	}

	albumTime := time.Date(tm.Year(), tm.Month(), tm.Day(), 0, 0, 0, 0, time.UTC)
	photo.AlbumDateTime = int(albumTime.Unix())
	photo.DateTime = int(tm.Unix())
	photo.Filename = sourceFilename
	return photo, nil
}
开发者ID:captainju,项目名称:gogal,代码行数:25,代码来源:GoGal.go

示例11: main

// Our programs starts executing here
func main() {
	// We need exactly 2 parameters: the first one is the program name,
	// the second one should be the photo we want to operate on
	if len(os.Args) != 2 {
		fmt.Println("Please give a single file name as an argument!")
		os.Exit(1)
	}

	// Retrieve the photo file name from the arguments array
	fileName := os.Args[1]

	// Try to opern the given file, error out on failure
	file, err := os.Open(fileName)
	exitOnError(err, "Couldn't open file")

	// Try to extract the EXIF data, error out on failure
	exifData, err := exif.Decode(file)
	exitOnError(err, "Couldn't find EXIF data")

	// Try to find a GPS coordinates entry in the EXIF data structure.
	// Error out on failure
	lat, long, err := exifData.LatLong()
	exitOnError(err, "Couldn't read GPS coordinates")

	// Create the final URL by using the Google Maps URL template
	url := fmt.Sprintf(googleMapsURLTemplate, lat, long)

	// Try to start the default browser for the current OS.
	// Show the computer URL on error, so that the user can still
	// access it manually
	err = open.Start(url)
	exitOnError(err, fmt.Sprintf(
		"Couldn't start the default browser, please visit %v manually", url))
}
开发者ID:valsinats42,项目名称:show-on-map,代码行数:35,代码来源:main.go

示例12: ParseExif

func (f *File) ParseExif() error {
	fpath := filepath.Join(f.TagDir, f.Filename)
	if f.Tempfile != "" {
		fpath = f.Tempfile
	}
	fp, err := os.Open(fpath)
	defer fp.Close()
	if err != nil {
		return err
	}

	f.Exif, err = exif.Decode(fp)
	if err != nil {
		return err
	}

	f.DateTime, err = f.Exif.DateTime()
	if err != nil {
		/// XXX: Log
	} else {
		f.DateTimeReadable = humanize.Time(f.DateTime)
	}

	f.Latitude, f.Longitude, err = f.Exif.LatLong()
	if err != nil {
		/// XXX: Log
	}

	return nil
}
开发者ID:denisbr,项目名称:filebin,代码行数:30,代码来源:file.go

示例13: imageMeta

func imageMeta(r io.ReadSeeker) (*Image, error) {
	conf, err := jpeg.DecodeConfig(r)
	if err != nil {
		return nil, fmt.Errorf("cannot decode JPEG: %s", err)
	}

	// compute image hash from image content
	oid := sha256.New()
	if _, err := io.Copy(oid, r); err != nil {
		return nil, fmt.Errorf("cannot compute SHA: %s", err)
	}
	img := Image{
		ImageID: encode(oid),
		Width:   conf.Width,
		Height:  conf.Height,
	}

	if _, err := r.Seek(0, os.SEEK_SET); err != nil {
		return nil, fmt.Errorf("cannot seek: %s", err)
	}
	if meta, err := exif.Decode(r); err != nil {
		log.Error("cannot extract EXIF metadata", "error", err.Error())
	} else {
		if orientation, err := meta.Get(exif.Orientation); err != nil {
			log.Debug("cannot extract image orientation",
				"decoder", "EXIF",
				"error", err.Error())
		} else {
			if o, err := orientation.Int(0); err != nil {
				log.Debug("cannot format orientation",
					"decoder", "EXIF",
					"error", err.Error())
			} else {
				img.Orientation = o
			}
		}
		if dt, err := meta.Get(exif.DateTimeOriginal); err != nil {
			log.Debug("cannot extract image datetime original",
				"decoder", "EXIF",
				"error", err.Error())
		} else {
			if raw, err := dt.StringVal(); err != nil {
				log.Debug("cannot format datetime original",
					"decoder", "EXIF",
					"error", err.Error())
			} else {
				img.Created, err = time.Parse("2006:01:02 15:04:05", raw)
				if err != nil {
					log.Debug("cannot parse datetime original",
						"decoder", "EXIF",
						"value", raw,
						"error", err.Error())
				}
			}
		}
	}

	return &img, nil
}
开发者ID:husio,项目名称:apps,代码行数:59,代码来源:handlers.go

示例14: processExif

// processExif attempts to rotate a JPEG based on the exif data. If the exif data
// cannot be decoded or the orientation tag not read, we return nil so that the image
// may continue to be uploaded. If there is an error encoding the image after
// modification, this is returned to the caller.
func (f *FileMetadataType) processExif() error {
	// Decode exif.
	ex, err := exif.Decode(bytes.NewReader(f.Content))
	if err != nil {
		return nil
	}
	// Get orientation tag.
	tag, err := ex.Get(exif.Orientation)
	if err != nil {
		return nil
	}
	orientation, err := tag.Int(0)
	if err != nil {
		return nil
	}

	var (
		angle            int
		flipMode         exifutil.FlipDirection
		switchDimensions bool
	)

	angle, flipMode, switchDimensions = exifutil.ProcessOrientation(int64(orientation))

	im, _, err := image.Decode(bytes.NewReader(f.Content))
	if err != nil {
		return err
	}

	if angle != 0 {
		im = exifutil.Rotate(im, angle)
	}

	if flipMode != 0 {
		im = exifutil.Flip(im, flipMode)
	}

	if switchDimensions {
		f.Width, f.Height = f.Height, f.Width
	}

	// Encode JPEG and replace f.Content.
	buf := new(bytes.Buffer)
	err = jpeg.Encode(buf, im, nil)
	if err != nil {
		return err
	}
	f.Content = buf.Bytes()

	// Update the hash and filesize based on changed content.
	sha1, err := h.SHA1(f.Content)
	if err != nil {
		return err
	}
	f.FileHash = sha1
	f.FileSize = int32(len(f.Content))

	return nil
}
开发者ID:riseofthetigers,项目名称:microcosm,代码行数:63,代码来源:file.go

示例15: rename

func rename(filename string, prefix string, suffix string, datetimeFormat string, counterLength int, dryrun bool) (result int, err error) {

	if !exists(filename) {
		result = 1
		err = os.ErrNotExist
		return
	}

	f, err := os.Open(filename)
	if err != nil {
		result = 1
		return
	}

	e, err := exif.Decode(f)
	if err != nil {
		result = 1
		return
	}

	t, err := e.DateTime()
	if err != nil {
		if !exif.IsTagNotPresentError(err) {
			result = 1
			return
		}

		/* Exifから撮影時刻が取得できない場合 => ファイルの更新時刻を使用 */
		info, _ := os.Stat(filename)
		t = info.ModTime()
		err = nil
	}

	datetime := t.Format(datetimeFormat)

	ext := filepath.Ext(filename)

	for i := 0; ; i++ {
		counter := fmt.Sprintf(fmt.Sprintf("_%%0%dd", counterLength), i)
		n := datetime + counter + ext

		if !exists(n) {
			newname := prefix + datetime + counter + suffix + ext
			log.Print("[RENAME] ", filename, " => ", newname)

			if !dryrun {
				err := os.Rename(filename, newname)
				if err != nil {
					log.Fatal(err)
				}
			}

			break
		}
	}

	result = 0
	return
}
开发者ID:aibax,项目名称:photoutils,代码行数:59,代码来源:exifrename.go


注:本文中的github.com/rwcarlsen/goexif/exif.Decode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。