user1938537
user1938537

Reputation: 19

Python name jpg with timestamp

(Solved)I am not understanding how to save my final jpg with a timestamp of the actual time and date. I can successfully save my camera jpg with my code below.

#!/usr/bin/python

import Image
import ImageChops
import sys
import glob
import os
import datetime
# get the date to add to caption and file name
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

try:
dir_images = sys.argv[1]
dir_results = sys.argv[2]
except IndexError:
print "No directories specified."

images = []
os.chdir('/media/SamsungDisk3/uhvo_replacement_test/images' )

for files in glob.glob("*.jpg"): 
images.append(files)
if len(images) is 2: 
    print images[0]
    background = Image.open(images[0])
    overlay = Image.open(images[1])

    print images[1]
    background = background.convert("RGBA")
    overlay = overlay.convert("RGBA")


    filename = "/home/tim/Desktop/final_stacked_images/final_result_" + datetime.datetime.now().strftime("%d_%m_%Y_%H:%M:%S") + ".jpg"
ImageChops.lighter(background, overlay).save(filename)

I am using Ubuntu 12.04 64 bit.... Thank you.

Upvotes: 1

Views: 2914

Answers (1)

hd1
hd1

Reputation: 34657

ImageChops.lighter(background, overlay).save('/home/tim/Desktop/final_stacked_images/final/result_{}.jpg'.format(datetime.datetime.now().strftime('%s')) 

... should sort you. If not, leave a comment with the error and I'll look into it further.

Upvotes: 1

Related Questions