Skip to content

Commit 3d2245a

Browse files
agormanAndy Gorman
and
Andy Gorman
authored
Adding the PrintGroupNames option (#67)
* Adding the PrintGroupNames option * Adding groupNumbers parameter go the PrintGroupNames method --------- Co-authored-by: Andy Gorman <andyg@apacesystems.com>
1 parent caa7545 commit 3d2245a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

exiftool.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,16 @@ func CoordFormant(format string) func(*Exiftool) error {
397397
}
398398
}
399399

400+
// PrintGroupNames prints the group names for each tag based on the pass group number(s), (activates Exiftool's '-G' paramater)
401+
// Sample :
402+
// e, err := NewExiftool(PrintGroupNames("0"))
403+
func PrintGroupNames(groupNumbers string) func(*Exiftool) error {
404+
return func(e *Exiftool) error {
405+
e.extraInitArgs = append(e.extraInitArgs, "-G"+groupNumbers)
406+
return nil
407+
}
408+
}
409+
400410
// BackupOriginal backs up the original file when writing the file metadata
401411
// instead of overwriting the original (activates Exiftool's '-overwrite_original' parameter)
402412
// Sample :

exiftool_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,40 @@ func TestCoordFormat(t *testing.T) {
432432
assert.Equal(t, "+43.467448", latitude)
433433
}
434434

435+
func TestPrintGroupNames(t *testing.T) {
436+
t.Parallel()
437+
438+
eWithout, err := NewExiftool()
439+
assert.Nil(t, err)
440+
defer eWithout.Close()
441+
metas := eWithout.ExtractMetadata("./testdata/20190404_131804.jpg")
442+
assert.Equal(t, 1, len(metas))
443+
assert.Nil(t, metas[0].Err)
444+
width, err := metas[0].GetString("ImageWidth")
445+
assert.Nil(t, err)
446+
assert.Equal(t, `64`, width)
447+
448+
eWith, err := NewExiftool(PrintGroupNames("0"))
449+
assert.Nil(t, err)
450+
defer eWith.Close()
451+
metas = eWith.ExtractMetadata("./testdata/20190404_131804.jpg")
452+
assert.Equal(t, 1, len(metas))
453+
assert.Nil(t, metas[0].Err)
454+
width, err = metas[0].GetString("File:ImageWidth")
455+
assert.Nil(t, err)
456+
assert.Equal(t, "64", width)
457+
458+
eWith, err = NewExiftool(PrintGroupNames("0:1:2:3:4:5:6:7"))
459+
assert.Nil(t, err)
460+
defer eWith.Close()
461+
metas = eWith.ExtractMetadata("./testdata/20190404_131804.jpg")
462+
assert.Equal(t, 1, len(metas))
463+
assert.Nil(t, metas[0].Err)
464+
width, err = metas[0].GetString("File:Image:Main:JPEG-SOF0:ID-ImageWidth:ImageWidth")
465+
assert.Nil(t, err)
466+
assert.Equal(t, "64", width)
467+
}
468+
435469
func TestSetExiftoolBinaryPath(t *testing.T) {
436470
t.Parallel()
437471

0 commit comments

Comments
 (0)