README.md (5890B)
1 # exif-terminator 2 3 `exif-terminator` removes exif data from images (jpeg and png currently supported) in a streaming manner. All you need to do is provide a reader of the image in, and exif-terminator will provide a reader of the image out. 4 5 Hasta la vista, baby! 6 7 ```text 8 .,lddxococ. 9 ..',lxO0Oo;'. 10 . .. .,coodO0klc:. 11 .,. ..','. .. .,..'. .':llxKXk' 12 .;c:cc;;,... .''.,l:cc. .....:l:,,:oo:.. 13 .,:ll'. .,;cox0OxOKKXX0kOOxlcld0X0d;,,,'. 14 .:xkl. .':cdKNWWWWMMMMMMMMMMWWNXK0KWNd. 15 .coxo,..:ollk0KKXNWMMMMMMMMMMWWXXXOoOM0; 16 ,oc,. .;cloxOKXXWWMMMMMMMMMMMWNXk;;OWO' 17 . ..;cdOKXNNWWMMMMMMMMMMMMWO,,ONO' 18 ...... ....;okOO000XWWMMMMMMMMMWXx;,ONNx. 19 .;c;. .:l'ckl. ..';looooolldolloooodolcc:;'.;oo:. 20 .oxl. ;:..OO. .. .. .,' .;. 21 .oko. .cc.'Ok. .:; .:,..';. 22 .cdc. .;;lc.,Ox. . .',,'..','. .dN0; .. .c:,,':. 23 .:oc. ,dxkl.,0x. . .. . .oNMMKc.. ...:l. 24 .:o:. cKXKl.,Ox. .. .lKWMMMXo,. ...''. 25 .:l; c0KKo.,0x. ...........';:lk0OKNNXKkl,..,;cxd' 26 .::' ;k00l.;0d. .. .,cloooddddxxddol;:ddloxdc,:odOWNc 27 .;,. ,ONKc.;0d. 'l,.. .:clllllllokKOl::cllclkKx'.lolxx' 28 .,. '0W0:.;0d. .:l,. .,:ccc:::oOXNXOkxdook0NWNx,,;c;. 29 ... .kX0c.;0d. .loc' .,::;;;;lk0kddoooooddooO0o',ld; 30 .. .oOkk:cKd. .... .;:,',;cxK0o::ldkOkkOkxod:';oKx. 31 .. :dlOolKO, '::'.';:oOK0xdddoollooxOx::ccOx. 32 .. ';:o,.xKo. .,;'...';lddolooodkkkdol:,::lc. 33 .. ...:..oOl. ........';:codxxOXKKKk;':;:kl 34 .. .,..lOc. .. ....,codxkxxxxxo:,,;lKO. .,;'.. 35 ... .. ck: ';,'. .;:cllloc,;;;colOK; .;odxxoc;. 36 ...,.... . :x; .;:cc;'. .,;::c:'..,kXk:xNc .':oook00x:. 37 . cKx. .'.. ':clllc,...'';:::cc:;.,kOo:xNx. .'codddoox 38 .. ,xxl;',col:;. .:cccccc;;;:lxkkOOkdc,,lolcxWO' ;kNKc.' 39 .,. .c' ':dkO0O; .. .;ccccccc:::cldxkxoll:;oolcdN0:.. .xWNk; 40 .:' .c',xXNKkOXo .,. .,:cccccllc::lloooolc:;lo:;oXKc,::. .kWWX 41 ,' .cONMWMWkco, ', .';::ccclolc:llolollcccodo;:KXl..cl,. ;KWN 42 '. .xWWWWMKc;; ....;' ',;::::coolclloooollc:,:o;;0Xx, .,:;... ,0Ko 43 . ,kKNWWXd,cdd0NXKk:,;;;'';::::coollllllllllc;;ccl0Nkc. ..';loOx' 44 'lxXWMXOOXNMMMMWWNNNWXkc;;;;;:cllccccccccc::lllkNWXd,. .cxO0Ol' 45 ,xKNWWXkkXWM0dxKNWWWMWNX0OOkl;;:c::cccc:,...:oONMMXOo;. :kOkOkl; 46 .;,;:;...,::. .;lokXKKNMMMWNOc,;;;,::;'...lOKNWNKkol:,..cKdcO0do 47 .:;... .. .,:okO0KNN0:.',,''''. ':xNMWKkxxOKXd,.cNk,:l:o 48 ``` 49 50 ## Why? 51 52 Exif removal is a pain in the arse. Most other libraries seem to parse the whole image into memory, then remove the exif data, then encode the image again. 53 54 `exif-terminator` differs in that it removes exif data *while scanning through the image bytes*, and it doesn't do any reencoding of the image. Bytes of exif data are simply all set to 0, and the image data is piped back out again into the returned reader. 55 56 The only exception is orientation data: if an image contains orientation data, this and only this data will be preserved since it's *actually useful*. 57 58 ## Example 59 60 You can run the following example with `go run ./example/main.go`: 61 62 ```go 63 package main 64 65 import ( 66 "io" 67 "os" 68 69 terminator "github.com/superseriousbusiness/exif-terminator" 70 ) 71 72 func main() { 73 // open a file 74 sloth, err := os.Open("./images/sloth.jpg") 75 if err != nil { 76 panic(err) 77 } 78 defer sloth.Close() 79 80 // get the length of the file 81 stat, err := sloth.Stat() 82 if err != nil { 83 panic(err) 84 } 85 86 // terminate! 87 out, err := terminator.Terminate(sloth, int(stat.Size()), "jpeg") 88 if err != nil { 89 panic(err) 90 } 91 92 // read the bytes from the reader 93 b, err := io.ReadAll(out) 94 if err != nil { 95 panic(err) 96 } 97 98 // save the file somewhere 99 if err := os.WriteFile("./images/sloth-clean.jpg", b, 0666); err != nil { 100 panic(err) 101 } 102 } 103 ``` 104 105 ## Credits 106 107 ### Libraries 108 109 `exif-terminator` borrows heavily from the two [`dsoprea`](https://github.com/dsoprea) libraries credited below. In fact, it's basically a hack on top of those libraries. Thanks `dsoprea`! 110 111 - [dsoprea/go-exif](https://github.com/dsoprea/go-exif): exif header reconstruction. [MIT License](https://spdx.org/licenses/MIT.html). 112 - [dsoprea/go-jpeg-image-structure](https://github.com/dsoprea/go-jpeg-image-structure): jpeg structure parsing. [MIT License](https://spdx.org/licenses/MIT.html). 113 - [dsoprea/go-png-image-structure](https://github.com/dsoprea/go-png-image-structure): png structure parsing. [MIT License](https://spdx.org/licenses/MIT.html). 114 - [stretchr/testify](https://github.com/stretchr/testify); test framework. [MIT License](https://spdx.org/licenses/MIT.html). 115 116 ## License 117 118 ![the gnu AGPL logo](https://www.gnu.org/graphics/agplv3-155x51.png) 119 120 `exif-terminator` is free software, licensed under the [GNU AGPL v3 LICENSE](LICENSE). 121 122 Copyright (C) 2022 SuperSeriousBusiness.