Difference between revisions of "TruxtonChildFileIO newexif"
Jump to navigation
Jump to search
(Created page with "This create new EXIF record from a file in Truxton. It automatically associates the parent file and media identifiers used in the EXIF table. =Syntax= <synta...") |
(→Sample) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
This create new EXIF record from a file in Truxton. | This create new EXIF record from a file in Truxton. | ||
| − | It automatically associates the parent file and media identifiers used in the [[EXIF Table | EXIF table. | + | It automatically associates the parent file and media identifiers used in the <code><nowiki>[</nowiki>[[EXIF Table|EXIF]]<nowiki>]</nowiki></code> table. |
=Syntax= | =Syntax= | ||
| − | < | + | <source lang="Python"> |
object newexif(); | object newexif(); | ||
| − | </ | + | </source> |
=Return value= | =Return value= | ||
| − | An EXIF object | + | An [[TruxtonEXIF|EXIF]] object |
=Sample= | =Sample= | ||
| − | + | <source lang="Python" highlight="28"> | |
| − | < | ||
import truxton | import truxton | ||
import shutil | import shutil | ||
| Line 58: | Line 57: | ||
if __name__ == "__main__": | if __name__ == "__main__": | ||
| − | main() | + | sys.exit(main()) |
| − | </ | + | </source> |
Latest revision as of 10:06, 3 February 2024
This create new EXIF record from a file in Truxton.
It automatically associates the parent file and media identifiers used in the [EXIF] table.
Syntax
object newexif();
Return value
An EXIF object
Sample
import truxton
import shutil
from datetime import datetime
from calendar import timegm
from pathlib import Path
EPOCH_AS_FILETIME = 116444736000000000
HUNDREDS_OF_NANOSECONDS = 10000000
def date_to_filetime(dt):
return EPOCH_AS_FILETIME + (timegm(dt.timetuple()) * HUNDREDS_OF_NANOSECONDS)
def add_file(parent_truxton_file, filename):
source_file = open(filename, "rb")
child = parent_truxton_file.newchild()
child.name = Path(filename).name
shutil.copyfileobj(source_file, child)
source_file.close()
child.save()
return child
def main():
t = truxton.create()
file = t.getfileid("5ec2a123-74d6-5da7-0653-4e6800000000")
child = add_file(file, "C:/photos/helper.jpg")
exif = child.newexif()
exif.gpstime = date_to_filetime(datetime.utcnow())
exif.devicetime = date_to_filetime(datetime.utcnow())
exif.shuttercount = 42
exif.make = "Sony"
exif.model = "BFG-9000"
exif.bodyserialnumber = "TX010188-PY"
exif.latitude = 39.038287
exif.longitude = -77.304136
exif.altitude = 100
exif.heading = 300
exif.focallength = 28.2
if exif.save() is True:
print( "New EXIF saved as id " + exif.id)
if __name__ == "__main__":
sys.exit(main())