diff --git a/.gitignore b/.gitignore index 2d88322..5e2ee9a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ *.iml .idea -img_output +exif-remove-tool/img_output diff --git a/img/11-tests.jpg b/exif-remove-tool/img/11-tests.jpg similarity index 100% rename from img/11-tests.jpg rename to exif-remove-tool/img/11-tests.jpg diff --git a/img/22-canon_tags.jpg b/exif-remove-tool/img/22-canon_tags.jpg similarity index 100% rename from img/22-canon_tags.jpg rename to exif-remove-tool/img/22-canon_tags.jpg diff --git a/img/28-hex_value.jpg b/exif-remove-tool/img/28-hex_value.jpg similarity index 100% rename from img/28-hex_value.jpg rename to exif-remove-tool/img/28-hex_value.jpg diff --git a/img/30-type_error.jpg b/exif-remove-tool/img/30-type_error.jpg similarity index 100% rename from img/30-type_error.jpg rename to exif-remove-tool/img/30-type_error.jpg diff --git a/img/32-lens_data.jpeg b/exif-remove-tool/img/32-lens_data.jpeg similarity index 100% rename from img/32-lens_data.jpeg rename to exif-remove-tool/img/32-lens_data.jpeg diff --git a/img/33-type_error.jpg b/exif-remove-tool/img/33-type_error.jpg similarity index 100% rename from img/33-type_error.jpg rename to exif-remove-tool/img/33-type_error.jpg diff --git a/img/35-empty.jpg b/exif-remove-tool/img/35-empty.jpg similarity index 100% rename from img/35-empty.jpg rename to exif-remove-tool/img/35-empty.jpg diff --git a/img/36-memory_error.jpg b/exif-remove-tool/img/36-memory_error.jpg similarity index 100% rename from img/36-memory_error.jpg rename to exif-remove-tool/img/36-memory_error.jpg diff --git a/img/42_IndexError.jpg b/exif-remove-tool/img/42_IndexError.jpg similarity index 100% rename from img/42_IndexError.jpg rename to exif-remove-tool/img/42_IndexError.jpg diff --git a/img/45-gps_ifd.jpg b/exif-remove-tool/img/45-gps_ifd.jpg similarity index 100% rename from img/45-gps_ifd.jpg rename to exif-remove-tool/img/45-gps_ifd.jpg diff --git a/img/46_UnicodeEncodeError.jpg b/exif-remove-tool/img/46_UnicodeEncodeError.jpg similarity index 100% rename from img/46_UnicodeEncodeError.jpg rename to exif-remove-tool/img/46_UnicodeEncodeError.jpg diff --git a/img/67-0_length_string.jpg b/exif-remove-tool/img/67-0_length_string.jpg similarity index 100% rename from img/67-0_length_string.jpg rename to exif-remove-tool/img/67-0_length_string.jpg diff --git a/img/BlueSquare.jpg b/exif-remove-tool/img/BlueSquare.jpg similarity index 100% rename from img/BlueSquare.jpg rename to exif-remove-tool/img/BlueSquare.jpg diff --git a/img/Canon_40D.jpg b/exif-remove-tool/img/Canon_40D.jpg similarity index 100% rename from img/Canon_40D.jpg rename to exif-remove-tool/img/Canon_40D.jpg diff --git a/img/Canon_40D_photoshop_import.jpg b/exif-remove-tool/img/Canon_40D_photoshop_import.jpg similarity index 100% rename from img/Canon_40D_photoshop_import.jpg rename to exif-remove-tool/img/Canon_40D_photoshop_import.jpg diff --git a/img/Canon_DIGITAL_IXUS_400.jpg b/exif-remove-tool/img/Canon_DIGITAL_IXUS_400.jpg similarity index 100% rename from img/Canon_DIGITAL_IXUS_400.jpg rename to exif-remove-tool/img/Canon_DIGITAL_IXUS_400.jpg diff --git a/img/Canon_PowerShot_S40.jpg b/exif-remove-tool/img/Canon_PowerShot_S40.jpg similarity index 100% rename from img/Canon_PowerShot_S40.jpg rename to exif-remove-tool/img/Canon_PowerShot_S40.jpg diff --git a/img/DSCN0010.jpg b/exif-remove-tool/img/DSCN0010.jpg similarity index 100% rename from img/DSCN0010.jpg rename to exif-remove-tool/img/DSCN0010.jpg diff --git a/img/DSCN0012.jpg b/exif-remove-tool/img/DSCN0012.jpg similarity index 100% rename from img/DSCN0012.jpg rename to exif-remove-tool/img/DSCN0012.jpg diff --git a/img/DSCN0021.jpg b/exif-remove-tool/img/DSCN0021.jpg similarity index 100% rename from img/DSCN0021.jpg rename to exif-remove-tool/img/DSCN0021.jpg diff --git a/img/DSCN0025.jpg b/exif-remove-tool/img/DSCN0025.jpg similarity index 100% rename from img/DSCN0025.jpg rename to exif-remove-tool/img/DSCN0025.jpg diff --git a/img/DSCN0027.jpg b/exif-remove-tool/img/DSCN0027.jpg similarity index 100% rename from img/DSCN0027.jpg rename to exif-remove-tool/img/DSCN0027.jpg diff --git a/img/DSCN0029.jpg b/exif-remove-tool/img/DSCN0029.jpg similarity index 100% rename from img/DSCN0029.jpg rename to exif-remove-tool/img/DSCN0029.jpg diff --git a/img/DSCN0038.jpg b/exif-remove-tool/img/DSCN0038.jpg similarity index 100% rename from img/DSCN0038.jpg rename to exif-remove-tool/img/DSCN0038.jpg diff --git a/img/DSCN0040.jpg b/exif-remove-tool/img/DSCN0040.jpg similarity index 100% rename from img/DSCN0040.jpg rename to exif-remove-tool/img/DSCN0040.jpg diff --git a/img/DSCN0042.jpg b/exif-remove-tool/img/DSCN0042.jpg similarity index 100% rename from img/DSCN0042.jpg rename to exif-remove-tool/img/DSCN0042.jpg diff --git a/img/Fujifilm_FinePix6900ZOOM.jpg b/exif-remove-tool/img/Fujifilm_FinePix6900ZOOM.jpg similarity index 100% rename from img/Fujifilm_FinePix6900ZOOM.jpg rename to exif-remove-tool/img/Fujifilm_FinePix6900ZOOM.jpg diff --git a/img/Fujifilm_FinePix_E500.jpg b/exif-remove-tool/img/Fujifilm_FinePix_E500.jpg similarity index 100% rename from img/Fujifilm_FinePix_E500.jpg rename to exif-remove-tool/img/Fujifilm_FinePix_E500.jpg diff --git a/img/Kodak_CX7530.jpg b/exif-remove-tool/img/Kodak_CX7530.jpg similarity index 100% rename from img/Kodak_CX7530.jpg rename to exif-remove-tool/img/Kodak_CX7530.jpg diff --git a/img/Konica_Minolta_DiMAGE_Z3.jpg b/exif-remove-tool/img/Konica_Minolta_DiMAGE_Z3.jpg similarity index 100% rename from img/Konica_Minolta_DiMAGE_Z3.jpg rename to exif-remove-tool/img/Konica_Minolta_DiMAGE_Z3.jpg diff --git a/img/NDM_8901.jpg b/exif-remove-tool/img/NDM_8901.jpg similarity index 100% rename from img/NDM_8901.jpg rename to exif-remove-tool/img/NDM_8901.jpg diff --git a/img/Nikon_COOLPIX_P1.jpg b/exif-remove-tool/img/Nikon_COOLPIX_P1.jpg similarity index 100% rename from img/Nikon_COOLPIX_P1.jpg rename to exif-remove-tool/img/Nikon_COOLPIX_P1.jpg diff --git a/img/Nikon_D70.jpg b/exif-remove-tool/img/Nikon_D70.jpg similarity index 100% rename from img/Nikon_D70.jpg rename to exif-remove-tool/img/Nikon_D70.jpg diff --git a/img/Olympus_C8080WZ.jpg b/exif-remove-tool/img/Olympus_C8080WZ.jpg similarity index 100% rename from img/Olympus_C8080WZ.jpg rename to exif-remove-tool/img/Olympus_C8080WZ.jpg diff --git a/img/PaintTool_sample.jpg b/exif-remove-tool/img/PaintTool_sample.jpg similarity index 100% rename from img/PaintTool_sample.jpg rename to exif-remove-tool/img/PaintTool_sample.jpg diff --git a/img/Panasonic_DMC-FZ30.jpg b/exif-remove-tool/img/Panasonic_DMC-FZ30.jpg similarity index 100% rename from img/Panasonic_DMC-FZ30.jpg rename to exif-remove-tool/img/Panasonic_DMC-FZ30.jpg diff --git a/img/Pentax_K10D.jpg b/exif-remove-tool/img/Pentax_K10D.jpg similarity index 100% rename from img/Pentax_K10D.jpg rename to exif-remove-tool/img/Pentax_K10D.jpg diff --git a/img/Ricoh_Caplio_RR330.jpg b/exif-remove-tool/img/Ricoh_Caplio_RR330.jpg similarity index 100% rename from img/Ricoh_Caplio_RR330.jpg rename to exif-remove-tool/img/Ricoh_Caplio_RR330.jpg diff --git a/img/Samsung_Digimax_i50_MP3.jpg b/exif-remove-tool/img/Samsung_Digimax_i50_MP3.jpg similarity index 100% rename from img/Samsung_Digimax_i50_MP3.jpg rename to exif-remove-tool/img/Samsung_Digimax_i50_MP3.jpg diff --git a/img/Sony_HDR-HC3.jpg b/exif-remove-tool/img/Sony_HDR-HC3.jpg similarity index 100% rename from img/Sony_HDR-HC3.jpg rename to exif-remove-tool/img/Sony_HDR-HC3.jpg diff --git a/img/WWL_(Polaroid)_ION230.jpg b/exif-remove-tool/img/WWL_(Polaroid)_ION230.jpg similarity index 100% rename from img/WWL_(Polaroid)_ION230.jpg rename to exif-remove-tool/img/WWL_(Polaroid)_ION230.jpg diff --git a/img/canon-ixus.jpg b/exif-remove-tool/img/canon-ixus.jpg similarity index 100% rename from img/canon-ixus.jpg rename to exif-remove-tool/img/canon-ixus.jpg diff --git a/img/canon_hdr_NO.jpg b/exif-remove-tool/img/canon_hdr_NO.jpg similarity index 100% rename from img/canon_hdr_NO.jpg rename to exif-remove-tool/img/canon_hdr_NO.jpg diff --git a/img/canon_hdr_YES.jpg b/exif-remove-tool/img/canon_hdr_YES.jpg similarity index 100% rename from img/canon_hdr_YES.jpg rename to exif-remove-tool/img/canon_hdr_YES.jpg diff --git a/img/foto_no_exif.jpg b/exif-remove-tool/img/foto_no_exif.jpg similarity index 100% rename from img/foto_no_exif.jpg rename to exif-remove-tool/img/foto_no_exif.jpg diff --git a/img/fujifilm-dx10.jpg b/exif-remove-tool/img/fujifilm-dx10.jpg similarity index 100% rename from img/fujifilm-dx10.jpg rename to exif-remove-tool/img/fujifilm-dx10.jpg diff --git a/img/fujifilm-mx1700.jpg b/exif-remove-tool/img/fujifilm-mx1700.jpg similarity index 100% rename from img/fujifilm-mx1700.jpg rename to exif-remove-tool/img/fujifilm-mx1700.jpg diff --git a/img/gps.jpg b/exif-remove-tool/img/gps.jpg similarity index 100% rename from img/gps.jpg rename to exif-remove-tool/img/gps.jpg diff --git a/img/iphone_hdr_NO.jpg b/exif-remove-tool/img/iphone_hdr_NO.jpg similarity index 100% rename from img/iphone_hdr_NO.jpg rename to exif-remove-tool/img/iphone_hdr_NO.jpg diff --git a/img/iphone_hdr_YES.jpg b/exif-remove-tool/img/iphone_hdr_YES.jpg similarity index 100% rename from img/iphone_hdr_YES.jpg rename to exif-remove-tool/img/iphone_hdr_YES.jpg diff --git a/img/jolla.jpg b/exif-remove-tool/img/jolla.jpg similarity index 100% rename from img/jolla.jpg rename to exif-remove-tool/img/jolla.jpg diff --git a/img/kodak-dc210.jpg b/exif-remove-tool/img/kodak-dc210.jpg similarity index 100% rename from img/kodak-dc210.jpg rename to exif-remove-tool/img/kodak-dc210.jpg diff --git a/img/kodak-dc240.jpg b/exif-remove-tool/img/kodak-dc240.jpg similarity index 100% rename from img/kodak-dc240.jpg rename to exif-remove-tool/img/kodak-dc240.jpg diff --git a/img/landscape_1.jpg b/exif-remove-tool/img/landscape_1.jpg similarity index 100% rename from img/landscape_1.jpg rename to exif-remove-tool/img/landscape_1.jpg diff --git a/img/landscape_2.jpg b/exif-remove-tool/img/landscape_2.jpg similarity index 100% rename from img/landscape_2.jpg rename to exif-remove-tool/img/landscape_2.jpg diff --git a/img/landscape_3.jpg b/exif-remove-tool/img/landscape_3.jpg similarity index 100% rename from img/landscape_3.jpg rename to exif-remove-tool/img/landscape_3.jpg diff --git a/img/landscape_4.jpg b/exif-remove-tool/img/landscape_4.jpg similarity index 100% rename from img/landscape_4.jpg rename to exif-remove-tool/img/landscape_4.jpg diff --git a/img/landscape_5.jpg b/exif-remove-tool/img/landscape_5.jpg similarity index 100% rename from img/landscape_5.jpg rename to exif-remove-tool/img/landscape_5.jpg diff --git a/img/landscape_6.jpg b/exif-remove-tool/img/landscape_6.jpg similarity index 100% rename from img/landscape_6.jpg rename to exif-remove-tool/img/landscape_6.jpg diff --git a/img/landscape_7.jpg b/exif-remove-tool/img/landscape_7.jpg similarity index 100% rename from img/landscape_7.jpg rename to exif-remove-tool/img/landscape_7.jpg diff --git a/img/landscape_8.jpg b/exif-remove-tool/img/landscape_8.jpg similarity index 100% rename from img/landscape_8.jpg rename to exif-remove-tool/img/landscape_8.jpg diff --git a/img/long_description.jpg b/exif-remove-tool/img/long_description.jpg similarity index 100% rename from img/long_description.jpg rename to exif-remove-tool/img/long_description.jpg diff --git a/img/nikon-e950.jpg b/exif-remove-tool/img/nikon-e950.jpg similarity index 100% rename from img/nikon-e950.jpg rename to exif-remove-tool/img/nikon-e950.jpg diff --git a/img/no_exif.jpg b/exif-remove-tool/img/no_exif.jpg similarity index 100% rename from img/no_exif.jpg rename to exif-remove-tool/img/no_exif.jpg diff --git a/img/olympus-c960.jpg b/exif-remove-tool/img/olympus-c960.jpg similarity index 100% rename from img/olympus-c960.jpg rename to exif-remove-tool/img/olympus-c960.jpg diff --git a/img/olympus-d320l.jpg b/exif-remove-tool/img/olympus-d320l.jpg similarity index 100% rename from img/olympus-d320l.jpg rename to exif-remove-tool/img/olympus-d320l.jpg diff --git a/img/portrait_1.jpg b/exif-remove-tool/img/portrait_1.jpg similarity index 100% rename from img/portrait_1.jpg rename to exif-remove-tool/img/portrait_1.jpg diff --git a/img/portrait_2.jpg b/exif-remove-tool/img/portrait_2.jpg similarity index 100% rename from img/portrait_2.jpg rename to exif-remove-tool/img/portrait_2.jpg diff --git a/img/portrait_3.jpg b/exif-remove-tool/img/portrait_3.jpg similarity index 100% rename from img/portrait_3.jpg rename to exif-remove-tool/img/portrait_3.jpg diff --git a/img/portrait_4.jpg b/exif-remove-tool/img/portrait_4.jpg similarity index 100% rename from img/portrait_4.jpg rename to exif-remove-tool/img/portrait_4.jpg diff --git a/img/portrait_5.jpg b/exif-remove-tool/img/portrait_5.jpg similarity index 100% rename from img/portrait_5.jpg rename to exif-remove-tool/img/portrait_5.jpg diff --git a/img/portrait_6.jpg b/exif-remove-tool/img/portrait_6.jpg similarity index 100% rename from img/portrait_6.jpg rename to exif-remove-tool/img/portrait_6.jpg diff --git a/img/portrait_7.jpg b/exif-remove-tool/img/portrait_7.jpg similarity index 100% rename from img/portrait_7.jpg rename to exif-remove-tool/img/portrait_7.jpg diff --git a/img/portrait_8.jpg b/exif-remove-tool/img/portrait_8.jpg similarity index 100% rename from img/portrait_8.jpg rename to exif-remove-tool/img/portrait_8.jpg diff --git a/img/ricoh-rdc5300.jpg b/exif-remove-tool/img/ricoh-rdc5300.jpg similarity index 100% rename from img/ricoh-rdc5300.jpg rename to exif-remove-tool/img/ricoh-rdc5300.jpg diff --git a/img/sanyo-vpcg250.jpg b/exif-remove-tool/img/sanyo-vpcg250.jpg similarity index 100% rename from img/sanyo-vpcg250.jpg rename to exif-remove-tool/img/sanyo-vpcg250.jpg diff --git a/img/sanyo-vpcsx550.jpg b/exif-remove-tool/img/sanyo-vpcsx550.jpg similarity index 100% rename from img/sanyo-vpcsx550.jpg rename to exif-remove-tool/img/sanyo-vpcsx550.jpg diff --git a/img/sony-cybershot.jpg b/exif-remove-tool/img/sony-cybershot.jpg similarity index 100% rename from img/sony-cybershot.jpg rename to exif-remove-tool/img/sony-cybershot.jpg diff --git a/img/sony-d700.jpg b/exif-remove-tool/img/sony-d700.jpg similarity index 100% rename from img/sony-d700.jpg rename to exif-remove-tool/img/sony-d700.jpg diff --git a/img/sony-powershota5.jpg b/exif-remove-tool/img/sony-powershota5.jpg similarity index 100% rename from img/sony-powershota5.jpg rename to exif-remove-tool/img/sony-powershota5.jpg diff --git a/exif-remove-tool/main.go b/exif-remove-tool/main.go new file mode 100644 index 0000000..eebc5b1 --- /dev/null +++ b/exif-remove-tool/main.go @@ -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 + } +} diff --git a/exif_remove.go b/exif_remove.go index 74afc71..2b31371 100644 --- a/exif_remove.go +++ b/exif_remove.go @@ -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" @@ -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{ diff --git a/readme.go b/readme.go new file mode 100644 index 0000000..fd1b801 --- /dev/null +++ b/readme.go @@ -0,0 +1,3 @@ +// exifremove clears exif information in jpg and png files + +package exifremove