Skip to content

Commit

Permalink
readme: Usage notes
Browse files Browse the repository at this point in the history
  • Loading branch information
neilpa committed May 8, 2020
1 parent 003dd06 commit 3686cdd
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,71 @@ Basic reading of [JPEG File Interchange Format (JFIF)][wiki-jfif] segments

[wiki-jfif]: https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_structure

## Install

Simply use `go get` to install the module

```
go get neilpa.me/go-jfif
```

Or just use it and rely on go modules to "do the right thing".

## Usage

TODO
Reading JFIF segments from an existing JPEG.

```go
package main

import (
"fmt"
"log"
"os"

"neilpa.me/go-jfif"
)

func main() {
f, err := os.Open("path/to/file.jpg")
if err != nil {
log.Fatal(err)
}

// See also jfif.ScanSegments which doesn't read the segment payload.
// This is used to detect the segment "signatures" for some APPn segments.
segs, err := jfif.DecodeSegments(f)
if err != nil {
log.Fatal(err)
}

for _, s := range segs {
sig, _, _ := s.AppPayload()
sig = jfif.CleanSig(sig)
fmt.Printf("%d\t%s\t%s\n", s.Length, s.Marker, sig)
}
}
```

Appending new segments to a JPEG. (Under the hood this edits a copy of the file before renaming the copy
to finalize the updates).

```go
package main

import (
"log"

"neilpa.me/go-jfif"
)

func main() {
err := jfif.Add("path/to/file.jpg", jfif.COM, []byte("adding a comment to this file"))
if err != nil {
log.Fatal(err)
}
}
```

## Tools

Expand Down

0 comments on commit 3686cdd

Please sign in to comment.