Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
module changes
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed Sep 2, 2019
1 parent e07f2d6 commit fa41d42
Show file tree
Hide file tree
Showing 84 changed files with 87 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

*.iml
.idea
img_output
exif-remove-tool/img_output
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
81 changes: 81 additions & 0 deletions exif-remove-tool/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package main

import (
"bytes"
"errors"
"fmt"
"image"
"image/jpeg"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/dsoprea/go-exif"
"github.com/dsoprea/go-jpeg-image-structure"
"github.com/dsoprea/go-png-image-structure"
"github.com/scottleedavis/go-exif-remove"
)

func main() {

if len(os.Args) == 1 {
var files []string
root := "img"
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if path != "img" {
files = append(files, path)
}
return nil
})
if err != nil {
panic(err)
}
pass := 0
fail := 0
for _, file := range files {
fmt.Println(file)
if b, err := handleFile(file); err != nil {
fail += 1
} else {
pass += 1
f := filepath.Base(file)
ioutil.WriteFile("img_output/"+f, b, 0644)
}
fmt.Println()
}

percentage := 100 * pass / (pass + fail)
fmt.Printf("Results (%v%%): %v pass, %v fail \n", int(percentage), pass, fail)
} else {
path := os.Args[1]
if b, err := handleFile(path); err != nil {
fmt.Printf(err.Error())
} else {
file := filepath.Base(path)
ioutil.WriteFile("img_output/"+file, b, 0644)
}
}

}

func handleFile(filepath string) ([]byte, error) {
if data, err := ioutil.ReadFile(filepath); err != nil {
fmt.Printf(err.Error())
return nil, err
} else {
_, err = jpeg.Decode(bytes.NewReader(data))
if err != nil {
fmt.Printf("ERROR: original image is corrupt" + err.Error() + "\n")
return nil, err
}
filtered, err := extractEXIF(data)
if err != nil {
if !strings.EqualFold(err.Error(), "no exif data") {
fmt.Printf("* " + err.Error() + "\n")
return nil, errors.New(err.Error())
}
}
return filtered, nil
}
}
73 changes: 2 additions & 71 deletions exif_remove.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package main
package exifremove

import (
"bytes"
"errors"
"fmt"
"image"
"image/jpeg"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/dsoprea/go-exif"
"github.com/dsoprea/go-jpeg-image-structure"
Expand All @@ -31,70 +25,7 @@ type MediaContext struct {
Media interface{}
}

func main() {

if len(os.Args) == 1 {
var files []string
root := "img"
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if path != "img" {
files = append(files, path)
}
return nil
})
if err != nil {
panic(err)
}
pass := 0
fail := 0
for _, file := range files {
fmt.Println(file)
if b, err := handleFile(file); err != nil {
fail += 1
} else {
pass += 1
f := filepath.Base(file)
ioutil.WriteFile("img_output/"+f, b, 0644)
}
fmt.Println()
}

percentage := 100 * pass / (pass + fail)
fmt.Printf("Results (%v%%): %v pass, %v fail \n", int(percentage), pass, fail)
} else {
path := os.Args[1]
if b, err := handleFile(path); err != nil {
fmt.Printf(err.Error())
} else {
file := filepath.Base(path)
ioutil.WriteFile("img_output/"+file, b, 0644)
}
}

}

func handleFile(filepath string) ([]byte, error) {
if data, err := ioutil.ReadFile(filepath); err != nil {
fmt.Printf(err.Error())
return nil, err
} else {
_, err = jpeg.Decode(bytes.NewReader(data))
if err != nil {
fmt.Printf("ERROR: original image is corrupt" + err.Error() + "\n")
return nil, err
}
filtered, err := extractEXIF(data)
if err != nil {
if !strings.EqualFold(err.Error(), "no exif data") {
fmt.Printf("* " + err.Error() + "\n")
return nil, errors.New(err.Error())
}
}
return filtered, nil
}
}

func extractEXIF(data []byte) ([]byte, error) {
func RemoveEXIF(data []byte) ([]byte, error) {
jmp := jpegstructure.NewJpegMediaParser()
pmp := pngstructure.NewPngMediaParser()
mc := &MediaContext{
Expand Down
3 changes: 3 additions & 0 deletions readme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// exifremove clears exif information in jpg and png files

package exifremove

0 comments on commit fa41d42

Please sign in to comment.