Preserve time stamp when shrinking an image
Posted
by Ckhrysze
on Stack Overflow
See other posts from Stack Overflow
or by Ckhrysze
Published on 2010-04-17T01:48:06Z
Indexed on
2010/04/17
1:53 UTC
Read the original article
Hit count: 365
My digital camera takes pictures with a very high resolution, and I have a PIL script to shrink them to 800x600 (or 600x800). However, it would be nice for the resultant file to retain the original timestamp. I noticed in the docs that I can use a File object instead of a name in PIL's image save method, but I don't know if that will help or not.
My code is basically name, ext = os.path.splitext(filename)
# open an image file (.bmp,.jpg,.png,.gif) you have in the working folder
image = Image.open(filename)
width = 800
height = 600
w, h = image.size
if h > w:
width = 600
height = 800
name = name + ".jpg"
shunken = image.resize((width, height), Image.ANTIALIAS)
shunken.save(name)
Thank you for any help you can give!
© Stack Overflow or respective owner