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

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()
Anunțuri

2 gânduri despre &8222;You won’t believe what I did to my pictures before uploading them online&8221;

  1. 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 tale sau dă clic pe un icon pentru a te autentifica:

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