Skip to content

Instantly share code, notes, and snippets.

@Salies
Last active March 1, 2022 10:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Salies/5f2cf5e8e40d04dfdc54f640050a46cd to your computer and use it in GitHub Desktop.
Save Salies/5f2cf5e8e40d04dfdc54f640050a46cd to your computer and use it in GitHub Desktop.
Image comment edition with piexif (example)
import piexif
def set_desc(imgPath, message):
exif_dict = piexif.load(imgPath)
exif_dict['0th'][40092] = string_to_array(message)
exif_bytes = piexif.dump(exif_dict)
piexif.insert(exif_bytes, imgPath)
return 1
def string_to_array(string):
stringArray = list(string)
asciiArray = ()
for letter in stringArray:
asciiArray = asciiArray + (ord(letter), 0)
asciiArray = asciiArray + (0, 0)
return asciiArray
#EXAMPLE: set_desc('e.jpg', 'hello bro')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment