Open GoogleCodeExporter opened 8 years ago
I have installed exiftool on my server and run:
exiftool -t -e -s IMG_0328.jpg
and I see that it does have proper DateTimeOriginal tag
anyone have any ideas on how to fix this?
Original comment by myk...@gmail.com
on 10 Sep 2009 at 4:29
when i upload a new picture the date is taken is saved as todays date and not
the
date stored in the image file
i've been poking around the source and can't figure out why this isn't working
for
the life of me
this functionality is very important to me :( can anyone offer any kind of
suggestions? i've tried a few versions of photologue and it's all working the
same
for me...
However, once the image is uploaded, I can use this code to return the correct
date_taken
from datetime import datetime
from photologue.models import Photo
img = Photo.objects.get(id=11)
exif_date = img.EXIF.get('EXIF DateTimeOriginal', None)
d, t = str.split(exif_date.values)
year, month, day = d.split(':')
hour, minute, second = t.split(':')
date_taken = datetime(int(year), int(month), int(day),
int(hour), int(minute), int(second))
print date_taken
... but this is not the value stored in the database...
ANY IDEAS?
Original comment by myk...@gmail.com
on 10 Sep 2009 at 8:58
DOES DATE TAKEN WORK FOR ANYONE!?!?!?
Original comment by myk...@gmail.com
on 11 Sep 2009 at 2:56
I added the following to the top of ImageModel.save()
def save(self, *args, **kwargs):
print self.EXIF
print self.date_taken
print '--------'
In my logs I show:
{}
None
--------
This leads me to believe the EXIF date is not populated.
Once the upload is complete, I did the following from shell (LocationImage is
my model):
l = list(LocationImage.objects.all())[-1]
l.EXIF
{'EXIF ApertureValue': (0x9202) Ratio=331919/62500 @ 500,
'EXIF CustomRendered': (0xA401) Short=0 @ 392,
'EXIF DateTimeDigitized': (0x9004) ASCII=2009:02:16 21:11:32 @ 472,
'EXIF DateTimeOriginal': (0x9003) ASCII=2009:02:16 21:11:32 @ 452,
'EXIF ExifVersion': (0x9000) Undefined=0221 @ 212,
'EXIF ExposureBiasValue': (0x9204) Signed Ratio=0 @ 508,
'EXIF ExposureMode': (0xA402) Short=Manual Exposure @ 404,
'EXIF ExposureProgram': (0x8822) Short=Manual @ 188,
'EXIF ExposureTime': (0x829A) Ratio=1/100 @ 436,
'EXIF FNumber': (0x829D) Ratio=63/10 @ 444,
'EXIF Flash': (0x9209) Short=Off @ 308,
'EXIF FocalLength': (0x920A) Ratio=33 @ 524,
'EXIF FocalPlaneResolutionUnit': (0xA210) Short=2 @ 380,
'EXIF FocalPlaneXResolution': (0xA20E) Ratio=324000/73 @ 532,
'EXIF FocalPlaneYResolution': (0xA20F) Ratio=2592000/583 @ 540,
'EXIF ISOSpeedRatings': (0x8827) Short=320 @ 200,
'EXIF MaxApertureValue': (0x9205) Ratio=35/8 @ 516,
'EXIF MeteringMode': (0x9207) Short=5L @ 296,
'EXIF SceneCaptureType': (0xA406) Short=0 @ 428,
'EXIF ShutterSpeedValue': (0x9201) Signed Ratio=415241/62500 @ 492,
'EXIF SubSecTimeDigitized': (0x9292) ASCII=00 @ 344,
'EXIF SubSecTimeOriginal': (0x9291) ASCII=00 @ 332,
'EXIF WhiteBalance': (0xA403) Short=Auto @ 416,
'Image DateTime': (0x0132) ASCII=2009:02:19 00:01:39 @ 134,
'Image ExifOffset': (0x8769) Long=154 @ 90,
'Image Make': (0x010F) ASCII=Canon @ 98,
'Image Model': (0x0110) ASCII=Canon EOS 40D @ 104,
'Image ResolutionUnit': (0x0128) Short=Pixels/Inch @ 66,
'Image XResolution': (0x011A) Ratio=240 @ 118,
'Image YResolution': (0x011B) Ratio=240 @ 126}
For whatever reason, the EXIF hash is not populated when the save runs.
Original comment by ash.chri...@gmail.com
on 27 Sep 2009 at 11:29
Ok, I figured out part of the problem:
self.image.path is not set with the PHOTOLOGUE_PATH until after the file is
saved, so
when the EXIF is accessed, it is trying to find the file, but can't since the
file is
neither on disk (the file isnt saved to disk until save is called) nor would it
be
able to fine the file if it were on disk since since the path is wrong.
I tested this using the following in the ImageModel.save() method
def save(self, *args, **kwargs):
print self.image.path
if self.date_taken is None:
try:
exif_date = self.EXIF.get('EXIF DateTimeOriginal', None)
if exif_date is not None:
d, t = str.split(exif_date.values)
year, month, day = d.split(':')
hour, minute, second = t.split(':')
self.date_taken = datetime(int(year), int(month), int(day),
int(hour), int(minute), int(second))
except:
pass
if self.date_taken is None:
self.date_taken = datetime.now()
if self._get_pk_val():
self.clear_cache()
super(ImageModel, self).save(*args, **kwargs)
self.pre_cache()
import time
time.sleep(5)
print self.image.path
/home/ashc/sandbox/myapp/src/site-media/aaaa.jpg
/home/ashc/sandbox/myapp/src/site-media/public/my_images/aaaa.jpg
A not so fancy solution is to save twice - change the save method to the
following:
def save(self, *args, **kwargs):
super(ImageModel, self).save(*args, **kwargs)
if self.date_taken is None:
try:
exif_date = self.EXIF.get('EXIF DateTimeOriginal', None)
if exif_date is not None:
d, t = str.split(exif_date.values)
year, month, day = d.split(':')
hour, minute, second = t.split(':')
self.date_taken = datetime(int(year), int(month), int(day),
int(hour), int(minute), int(second))
except:
pass
if self.date_taken is None:
self.date_taken = datetime.now()
if self._get_pk_val():
self.clear_cache()
super(ImageModel, self).save(*args, **kwargs)
self.pre_cache()
Original comment by ash.chri...@gmail.com
on 28 Sep 2009 at 12:00
I'm using:
import os
import datetime
def get_image_path(instance,filename):
datetoday=datetime.datetime.now()
return os.path.join('photos',str(datetoday.year), str(datetoday.month),
str(datetoday.day), filename)
as a callable for get_storage_path. However, it is not initialized when I first
save
my instance. It seems upload_to is set to MEDIA_ROOT/filename on the first save.
But this is not where the file is saved, so then the EXIF module doesn't find
the
file and details from the exif header can not be accessed and stored in db.
On the second save, get_storage_path works as intended.
Original comment by paul.sk...@gmail.com
on 10 Nov 2009 at 10:28
Original issue reported on code.google.com by
myk...@gmail.com
on 10 Sep 2009 at 4:15