GoToSocial/vendor/github.com/superseriousbusiness/exif-terminator
tobi 2462c5fe22
[chore] bump exif-terminator to 0.4.0 (#747)
2022-08-10 14:10:46 +02:00
..
LICENSE use exif-terminator 2022-01-23 14:41:31 +01:00
README.md [bugfix] Don't remove jpeg orientation metadata (#663) 2022-06-23 15:38:19 +02:00
jpeg.go [chore] bump exif-terminator to 0.4.0 (#747) 2022-08-10 14:10:46 +02:00
logger.go [bugfix] Fix images not being processed correctly sometimes (#437) 2022-03-21 19:46:51 +01:00
png.go use exif-terminator 2022-01-23 14:41:31 +01:00
terminator.go [chore] bump exif-terminator to 0.4.0 (#747) 2022-08-10 14:10:46 +02:00

README.md

exif-terminator

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.

Hasta la vista, baby!

                                                  .,lddxococ.                   
                                                 ..',lxO0Oo;'.                  
                                               .  .. .,coodO0klc:.              
                           .,.   ..','.  ..  .,..'.      .':llxKXk'             
                          .;c:cc;;,...   .''.,l:cc. .....:l:,,:oo:..            
                          .,:ll'.   .,;cox0OxOKKXX0kOOxlcld0X0d;,,,'.           
                          .:xkl. .':cdKNWWWWMMMMMMMMMMWWNXK0KWNd.               
                         .coxo,..:ollk0KKXNWMMMMMMMMMMWWXXXOoOM0;               
                         ,oc,.  .;cloxOKXXWWMMMMMMMMMMMWNXk;;OWO'               
                          .      ..;cdOKXNNWWMMMMMMMMMMMMWO,,ONO'               
          ......                ....;okOO000XWWMMMMMMMMMWXx;,ONNx.              
.;c;.     .:l'ckl.              ..';looooolldolloooodolcc:;'.;oo:.              
.oxl.      ;:..OO.              .. ..             .,'         .;.               
.oko.     .cc.'Ok.                                .:;     .:,..';.              
.cdc.   .;;lc.,Ox.              .   .',,'..','.  .dN0; .. .c:,,':.              
.:oc.   ,dxkl.,0x.              .     ..   .    .oNMMKc..   ...:l.              
.:o:.   cKXKl.,Ox.              ..             .lKWMMMXo,.  ...''.              
.:l;    c0KKo.,0x.               ...........';:lk0OKNNXKkl,..,;cxd'             
.::'    ;k00l.;0d.        ..     .,cloooddddxxddol;:ddloxdc,:odOWNc             
.;,.    ,ONKc.;0d.        'l,..   .:clllllllokKOl::cllclkKx'.lolxx'             
.,.     '0W0:.;0d.        .:l,.   .,:ccc:::oOXNXOkxdook0NWNx,,;c;.              
...     .kX0c.;0d.         .loc'  .,::;;;;lk0kddoooooddooO0o',ld;               
..      .oOkk:cKd.          ....  .;:,',;cxK0o::ldkOkkOkxod:';oKx.              
..       :dlOolKO,                '::'.';:oOK0xdddoollooxOx::ccOx.              
..       ';:o,.xKo.               .,;'...';lddolooodkkkdol:,::lc.               
..       ...:..oOl.                ........';:codxxOXKKKk;':;:kl                
..         .,..lOc.               ..     ....,codxkxxxxxo:,,;lKO.  .,;'..       
...         .. ck:                ';,'.       .;:cllloc,;;;colOK;  .;odxxoc;.   
...,....    .  :x;                .;:cc;'.     .,;::c:'..,kXk:xNc   .':oook00x:.
      .        cKx.    .'..        ':clllc,...'';:::cc:;.,kOo:xNx.    .'codddoox
      ..       ,xxl;',col:;.       .:cccccc;;;:lxkkOOkdc,,lolcxWO'       ;kNKc.'
     .,.       .c' ':dkO0O;     .. .;ccccccc:::cldxkxoll:;oolcdN0:..      .xWNk;
     .:'       .c',xXNKkOXo    .,. .,:cccccllc::lloooolc:;lo:;oXKc,::.     .kWWX
      ,'       .cONMWMWkco,    ',  .';::ccclolc:llolollcccodo;:KXl..cl,.    ;KWN
      '.       .xWWWWMKc;; ....;'   ',;::::coolclloooollc:,:o;;0Xx, .,:;... ,0Ko
      .        ,kKNWWXd,cdd0NXKk:,;;;'';::::coollllllllllc;;ccl0Nkc.   ..';loOx'
               'lxXWMXOOXNMMMMWWNNNWXkc;;;;;:cllccccccccc::lllkNWXd,.   .cxO0Ol'
               ,xKNWWXkkXWM0dxKNWWWMWNX0OOkl;;:c::cccc:,...:oONMMXOo;.  :kOkOkl;
               .;,;:;...,::.  .;lokXKKNMMMWNOc,;;;,::;'...lOKNWNKkol:,..cKdcO0do
                       .:;...  .. .,:okO0KNN0:.',,''''. ':xNMWKkxxOKXd,.cNk,:l:o

Why?

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.

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.

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.

Example

You can run the following example with go run ./example/main.go:

package main

import (
  "io"
  "os"

  terminator "github.com/superseriousbusiness/exif-terminator"
)

func main() {
  // open a file
  sloth, err := os.Open("./images/sloth.jpg")
  if err != nil {
    panic(err)
  }
  defer sloth.Close()

  // get the length of the file
  stat, err := sloth.Stat()
  if err != nil {
    panic(err)
  }

  // terminate!
  out, err := terminator.Terminate(sloth, int(stat.Size()), "jpeg")
  if err != nil {
    panic(err)
  }

  // read the bytes from the reader
  b, err := io.ReadAll(out)
  if err != nil {
    panic(err)
  }

  // save the file somewhere
  if err := os.WriteFile("./images/sloth-clean.jpg", b, 0666); err != nil {
    panic(err)
  }
}

Credits

Libraries

exif-terminator borrows heavily from the two dsoprea libraries credited below. In fact, it's basically a hack on top of those libraries. Thanks dsoprea!

License

the gnu AGPL logo

exif-terminator is free software, licensed under the GNU AGPL v3 LICENSE.

Copyright (C) 2022 SuperSeriousBusiness.