File tree Expand file tree Collapse file tree 1 file changed +63
-1
lines changed
Expand file tree Collapse file tree 1 file changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,71 @@ Basic reading of [JPEG File Interchange Format (JFIF)][wiki-jfif] segments
66
77[ wiki-jfif ] : https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_structure
88
9+ ## Install
10+
11+ Use ` go get ` to install the module
12+
13+ ```
14+ go get neilpa.me/go-jfif
15+ ```
16+
17+ Or use it and rely on go modules to "do the right thing".
18+
919## Usage
1020
11- TODO
21+ Reading JFIF segments from an existing JPEG.
22+
23+ ``` go
24+ package main
25+
26+ import (
27+ " fmt"
28+ " log"
29+ " os"
30+
31+ " neilpa.me/go-jfif"
32+ )
33+
34+ func main () {
35+ f , err := os.Open (" path/to/file.jpg" )
36+ if err != nil {
37+ log.Fatal (err)
38+ }
39+
40+ // See also jfif.ScanSegments which doesn't read the segment payload.
41+ // This is used to detect the segment "signatures" for some APPn segments.
42+ segs , err := jfif.DecodeSegments (f)
43+ if err != nil {
44+ log.Fatal (err)
45+ }
46+
47+ for _ , s := range segs {
48+ sig , _ , _ := s.AppPayload ()
49+ sig = jfif.CleanSig (sig)
50+ fmt.Printf (" %d \t %s \t %s \n " , s.Length , s.Marker , sig)
51+ }
52+ }
53+ ```
54+
55+ Appending new segments to a JPEG. (Under the hood this edits a copy of the file before renaming the copy
56+ to finalize the updates).
57+
58+ ``` go
59+ package main
60+
61+ import (
62+ " log"
63+
64+ " neilpa.me/go-jfif"
65+ )
66+
67+ func main () {
68+ err := jfif.Add (" path/to/file.jpg" , jfif.COM , []byte (" adding a comment to this file" ))
69+ if err != nil {
70+ log.Fatal (err)
71+ }
72+ }
73+ ```
1274
1375## Tools
1476
You can’t perform that action at this time.
0 commit comments