Skip to content

Commit 0cce067

Browse files
authored
Changelog 1.7.0 (#49)
* Add an example for metadata writing * Fix CI (go 1.13 compatibility) * Update README.MD
1 parent f6dcf9c commit 0cce067

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

README.MD

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
**go-exiftool** is a golang library that wraps [ExifTool](https://www.sno.phy.queensu.ca/~phil/exiftool/).
1010

11-
[ExifTool](https://www.sno.phy.queensu.ca/~phil/exiftool/)'s purpose is to extract as much metadata as possible (EXIF, IPTC, XMP, GPS, ...) from [a lots of differents file types](https://www.sno.phy.queensu.ca/~phil/exiftool/#supported) (Office documents, pictures, movies, PDF, ...).
11+
[ExifTool](https://www.sno.phy.queensu.ca/~phil/exiftool/)'s purpose is to extract and update as much metadata as possible (EXIF, IPTC, XMP, GPS, ...) from [a lots of differents file types](https://www.sno.phy.queensu.ca/~phil/exiftool/#supported) (Office documents, pictures, movies, PDF, ...).
1212

1313
**go-exiftool** uses [ExifTool](https://www.sno.phy.queensu.ca/~phil/exiftool/)'s *`stay_open`* feature to [optimize performance](https://www.sno.phy.queensu.ca/~phil/exiftool/#performance).
1414

@@ -22,6 +22,8 @@ By default, `go-exiftool` binary will look for `exiftool` binary in $PATH, but a
2222

2323
## Usage
2424

25+
### Metadata extraction
26+
2527
```go
2628
et, err := exiftool.NewExiftool()
2729
if err != nil {
@@ -62,6 +64,10 @@ Output :
6264
(...)
6365
```
6466

67+
### Metadata update
68+
69+
See [example function ExampleExiftool_Write in exiftool_sample_test.go](exiftool_sample_test.go)
70+
6571
## Changelog
6672

6773
- v1.1.0 : initial release
@@ -87,4 +93,6 @@ Output :
8793
- [v1.6.1](https://github.com/barasher/go-exiftool/milestone/11)
8894
- "SetExiftoolBinaryPath" functional option : specify where to find exiftool binary (default : $path)
8995
- [v1.6.2](https://github.com/barasher/go-exiftool/milestone/12)
90-
- Several improvements (thanks to [Dale Hui](https://github.com/dhui))
96+
- Several improvements (thanks to [Dale Hui](https://github.com/dhui))
97+
- [v1.7.0](https://github.com/barasher/go-exiftool/milestone/13)
98+
- Add metadata writing capabilities (thanks to [Dale Hui](https://github.com/dhui))

exiftool_sample_test.go

+51-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package exiftool_test
22

33
import (
44
"fmt"
5+
"io"
6+
"os"
7+
8+
"io/ioutil"
9+
"path/filepath"
510

611
"github.com/barasher/go-exiftool"
712
)
813

9-
func ExampleExiftool() {
14+
func ExampleExiftool_Read() {
1015
et, err := exiftool.NewExiftool()
1116
if err != nil {
1217
fmt.Printf("Error when intializing: %v\n", err)
@@ -27,3 +32,48 @@ func ExampleExiftool() {
2732
}
2833
}
2934
}
35+
36+
func copyFile(src, dest string) (err error) {
37+
s, err := os.Open(src)
38+
if err != nil {
39+
return err
40+
}
41+
defer s.Close()
42+
43+
d, err := os.Create(dest)
44+
if err != nil {
45+
return err
46+
}
47+
defer d.Close()
48+
49+
_, err = io.Copy(d, s)
50+
if err != nil {
51+
return err
52+
}
53+
return nil
54+
}
55+
56+
func ExampleExiftool_Write() {
57+
// error handling are skipped in this example
58+
59+
tmpDir, _ := ioutil.TempDir("", "ExampleExiftoolWrite")
60+
testFile := filepath.Join(tmpDir, "20190404_131804.jpg")
61+
copyFile("testdata/20190404_131804.jpg", testFile)
62+
63+
e, _ := exiftool.NewExiftool()
64+
defer e.Close()
65+
originals := e.ExtractMetadata(testFile)
66+
title, _ := originals[0].GetString("Title")
67+
fmt.Println("title:" + title)
68+
69+
originals[0].SetString("Title", "newTitle")
70+
e.WriteMetadata(originals)
71+
72+
altered := e.ExtractMetadata(testFile)
73+
title, _ = altered[0].GetString("Title")
74+
fmt.Println("title:" + title)
75+
76+
// Output:
77+
// title:
78+
// title:newTitle
79+
}

0 commit comments

Comments
 (0)