Skip to content

Commit

Permalink
Rework implementation to use exiftool as the facit
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jul 10, 2024
1 parent e2e8168 commit e280471
Show file tree
Hide file tree
Showing 181 changed files with 11,149 additions and 420 deletions.
Binary file added .DS_Store
Binary file not shown.
62 changes: 33 additions & 29 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
on:
push:
branches: [ main ]
branches: [main]
pull_request:
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.21.x,1.22.x]
go-version: [1.21.x, 1.22.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
shell: bash
- name: Install golint
run: go install golang.org/x/lint/golint@latest
shell: bash
- name: Update PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Checkout code
uses: actions/checkout@v3
- name: Fmt
if: matrix.platform != 'windows-latest' # :(
run: "diff <(gofmt -d .) <(printf '')"
shell: bash
- name: Vet
run: go vet ./...
- name: Staticcheck
run: staticcheck ./...
- name: Lint
run: golint ./...
- name: Test
run: go test -race ./...
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
shell: bash
- name: Install golint
run: go install golang.org/x/lint/golint@latest
shell: bash
- name: Update PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Checkout code
uses: actions/checkout@v3
- name: Fmt
if: matrix.platform != 'windows-latest' # :(
run: "diff <(gofmt -d .) <(printf '')"
shell: bash
- name: Vet
run: go vet ./...
- name: Staticcheck
run: staticcheck ./...
- name: Lint
run: golint ./...
- name: Test
run: go test -race ./... -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
[![Tests on Linux, MacOS and Windows](https://github.com/bep/imagemeta/workflows/Test/badge.svg)](https://github.com/bep/imagemeta/actions?query=workflow:Test)
[![Go Report Card](https://goreportcard.com/badge/github.com/bep/imagemeta)](https://goreportcard.com/report/github.com/bep/imagemeta)
[![codecov](https://codecov.io/gh/bep/imagemeta/branch/master/graph/badge.svg)](https://codecov.io/gh/bep/imagemeta)
[![GoDoc](https://godoc.org/github.com/bep/imagemeta?status.svg)](https://godoc.org/github.com/bep/imagemeta)

# Work in progress

This is not ready, yet, but the goal is to use this as the library to read image metadata in Hugo. The existing Go libraries I have found is not maintained anymore and too complex to build on top of. The goal of this library is to be relatively small and simple, but I may prove myself wrong.
## When in doubt, Exiftools is right

The output of this library is tested against `exiftool -n -json`. This means, for example, that:

* We use f-numbers and not APEX for aperture values.
* We use seconds and not APEX for shutter speed values.
* EXIF field definitions are fetched from this table: https://exiftool.org/TagNames/EXIF.html
* IPTC field definitions are fetched from this table: https://exiftool.org/TagNames/IPTC.html
* The XMP handling is currently very simple, you can supply your own XMP handler (see the `HandleXMP` option) if you need more.


## Development

Many of the tests depends on generated golden files. To update these, run:

```bash
go generate ./gen
```

Note that you need a working `exiftool` and updated binary in your `PATH` for this to work. This was tested OK with:

```
exiftool -ver
12.76
```
1 change: 0 additions & 1 deletion exif_fields.go

This file was deleted.

35 changes: 35 additions & 0 deletions exiftype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//go:generate go run main.go
package main

import (
"bytes"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)

func main() {
outDir := "testdata_exiftool"
os.RemoveAll(outDir)
if err := os.MkdirAll(outDir, 0o755); err != nil {
log.Fatal(err)
}
base := "../testdata"

if err := filepath.Walk(base, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() || strings.HasPrefix(info.Name(), ".") {
return nil
}

basePath := strings.TrimPrefix(path, base)

var buf bytes.Buffer
cmd := exec.Command("exiftool", path, "-json", "-n", "-g", "-e")
cmd.Stdout = &buf
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
return err
}

outFilename := filepath.Join(outDir, basePath+".json")
if err := os.MkdirAll(filepath.Dir(outFilename), 0o755); err != nil {
return err
}

if err := os.WriteFile(outFilename, buf.Bytes(), 0o644); err != nil {
return err
}

return nil
}); err != nil {
log.Fatal(err)
}
}
Loading

0 comments on commit e280471

Please sign in to comment.