Alex's Weblog

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Alătură-te lângă 1 urmăritor

  • Noiembrie 2013
    L M M M V S D
    « Mar   Dec »
     123
    45678910
    11121314151617
    18192021222324
    252627282930  

You won’t believe what I did to my pictures before uploading them online

Posted by alecs1 pe 2013-11-14

Bansky_one_nation_under_cctv

Uploaded a bunch of pictures to Facebook, but felt like I had to remove EXIF from them before😀


#assumes that imagemagick is installed, it contains the "convert" program:

import os, sys
import subprocess

#assumes absolute path
def stripExifInfo(path, extension):
  for fileName in os.listdir(path):
    #print fileName
    absFileName = os.path.join(path, fileName)
    if absFileName.endswith(extension):
      print "Will call " + "convert " + absFileName + " " + "-strip" + " " + absFileName
      subprocess.call(["convert", absFileName, "-strip", absFileName])
      
def renameFiles(path, extension):
  crtNumber = -1
  for fileName in sorted(os.listdir(path)):
    absFileName = os.path.join(path, fileName)
    if absFileName.endswith(extension):
      #use os.rename
      crtNumber += 1
      newFileName = os.path.join(path, str(crtNumber) + "." + extension)
      while(os.path.exists(newFileName)):
	crtNumber += 1
	newFileName = os.join(path, str(crtNumber) + "." + extension)
	pass
      print "Will rename " + absFileName + " to " + newFileName
      os.rename(absFileName, newFileName)
    else:
      #uninterestign extension
      pass

def main():
  crtArg = 0
  while crtArg < len(sys.argv):
    print str(crtArg) + " - " + sys.argv[crtArg]
    crtArg += 1
  if len(sys.argv) < 3:
    sys.exit("Usage: remove-exif-info.py   [-r]\n" +
      "-r - also rename all files touched\n" +
      "ex: python remove-exif-info.py \"/home/user/pictures-for-web\" \"jpg\" -r\n")
      
  path = sys.argv[1]
  extension = sys.argv[2]
  doRename = ""
  if len(sys.argv) > 3:
    doRename = sys.argv[3]
    
  print "\n\nStripping exif info"
  stripExifInfo(path, extension)
  if doRename == "-r":
    print "\n\nAlso renaming all files"
    renameFiles(path, extension)
  pass
      
if __name__ == "__main__":
    main()

2 Răspunsuri to “You won’t believe what I did to my pictures before uploading them online”

  1. Teodor said

    Poate era mai simplu sa faci un script shell sau perl din care doar sa apelezi imagemagick-ul? pare overkill in python

Lasă un răspuns

Completează mai jos detaliile despre tine sau dă clic pe un icon pentru autentificare:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s

 
%d blogeri au apreciat asta: