Hacking With Python #14 - Editing or Removing Meta Data From Images

View previous topic View next topic Go down

Hacking With Python #14 - Editing or Removing Meta Data From Images

Post by jamied_uk on 6th November 2015, 13:53

Code:
<iframe width="560" height="315" src="https://www.youtube.com/embed/1C5ZNtWc4_M" frameborder="0" allowfullscreen></iframe>

https://www.mediafire.com/folder/atao6cya3yodh/HackingWithPython_14_-_Editing_%26_removing_metadata

Code:
//Extract Meta Data
// https://youtu.be/1C5ZNtWc4_M



http://Exifedit.py//



import argparse

import pyexiv2



def ClearAllMetadata(imgname, preserve):

    metadata = pyexiv2.ImageMetadata(imgname)

    metadata.read()

    metadata.clear()

    metadata.write(preserve)



def ModifyMode(imgname, preserve):

    metadata = pyexiv2.ImageMetadata(imgname)

    metadata.read()

    for key, value in metadata.iteritems():

        print key, value.raw_value

    modkey = raw_input("Key to modify (q to quit):")

    while not modkey == 'q':

        print "Editing:"+str(metadata[modkey].raw_value)

        modvalue = raw_input("New Value: (q to quit):")

        if modvalue == 'q':

            break

        metadata[modkey].raw_value = str(modvalue)

        modkey = raw_input("Key to modify (q to quit):")

    metadata.write(preserve)



def Main():

    parser = argparse.ArgumentParser()

    parser.add_argument("img", help="Image file to manipulate")

    parser.add_argument("--clear", "-c", help="Clear all meta data from the file", action="store_true")

    parser.add_argument("--preserve", "-p", help="Preserve image modified date", action="store_true")

    args = parser.parse_args()

    if args.img:

        if args.clear:

            ClearAllMetadata(args.img, args.preserve)

        else:

            ModifyMode(args.img, args.preserve)

    else:

        print parser.usage



if __name__ == '__main__':

    Main()





jamied_uk
Admin

Posts : 1981
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum