示例#1
0
文件: exif.go 项目: quincy/exif
func (self *Data) Open(file string) error {

	cfile := C.CString(file)

	self.ed = C.exif_data_new_from_file(cfile)
	defer C.free(unsafe.Pointer(self.ed))

	C.free(unsafe.Pointer(cfile))

	if self.ed == nil {
		return fmt.Errorf("No EXIF data in file: %s\n", file)
	}

	values := C.exif_dump(self.ed)

	for true {
		value := C.pop_exif_value(values)
		if value == nil {
			break
		} else {
			self.Tags[strings.Trim(C.GoString((*value).name), " ")] = strings.Trim(C.GoString((*value).value), " ")
		}
		C.free_exif_value(value)
	}

	C.free(unsafe.Pointer(values))

	return nil
}
示例#2
0
文件: exif.go 项目: xiam/exif
func (d *Data) parseExifData(exifData *C.ExifData) error {
	values := C.exif_dump(exifData)
	defer C.free(unsafe.Pointer(values))

	for {
		value := C.pop_exif_value(values)
		if value == nil {
			break
		} else {
			d.Tags[strings.Trim(C.GoString((*value).name), " ")] = strings.Trim(C.GoString((*value).value), " ")
		}
		C.free_exif_value(value)
	}

	return nil
}
示例#3
0
文件: main.go 项目: imtaco/exif
func (self *Data) parseExifData(exifData *C.ExifData) error {
	values := C.exif_dump(exifData)

	for {
		value := C.pop_exif_value(values)
		if value == nil {
			break
		} else {
			tag := strings.Trim(C.GoString((*value).name), " ")
			if 0x927c == (*value).tag || 0x9286 == (*value).tag {
				// for makernote and usercomment, we just store b64encoded value
				self.Tags[tag] = base64.StdEncoding.EncodeToString(
					C.GoBytes(unsafe.Pointer((*value).value), (*value).length))
			} else {
				self.Tags[tag] = strings.Trim(C.GoString((*value).value), " ")
			}
		}
		C.free_exif_value(value)
	}

	C.free(unsafe.Pointer(values))

	return nil
}