Coder Social home page Coder Social logo

superseriousbusiness / exif-terminator Goto Github PK

View Code? Open in Web Editor NEW
16.0 4.0 3.0 10.94 MB

READ ONLY - Migrated to Codeberg

Home Page: https://codeberg.org/superseriousbusiness/exif-terminator

License: GNU Affero General Public License v3.0

Go 100.00%

exif-terminator's Introduction

This repository now lives at Codeberg: https://codeberg.org/superseriousbusiness/exif-terminator

This repository is a read-only archive.

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.

exif-terminator's People

Contributors

ftrvxmtrx avatar tsmethurst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.