Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dependency to ExifTool #10

Closed
derneuere opened this issue Nov 30, 2020 · 2 comments
Closed

Change dependency to ExifTool #10

derneuere opened this issue Nov 30, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@derneuere
Copy link
Member

We should refactor all calls of ExifRead and refactor it to direct calls of ExifTool via pyexiftool. This will allow us to read all the file formats including video formats.

@derneuere derneuere added the enhancement New feature or request label Nov 30, 2020
@derneuere derneuere changed the title Change dependencies to ExifTool Change dependency to ExifTool Dec 6, 2020
@derneuere
Copy link
Member Author

def rotate_image(image):
# If no ExifTags, no rotating needed.
try:
# Grab orientation value.
image_exif = image._getexif()
image_orientation = image_exif[274]
# Rotate depending on orientation.
if image_orientation == 2:
image = image.transpose(PIL.Image.FLIP_LEFT_RIGHT)
if image_orientation == 3:
image = image.transpose(PIL.Image.ROTATE_180)
if image_orientation == 4:
image = image.transpose(PIL.Image.FLIP_TOP_BOTTOM)
if image_orientation == 5:
image = image.transpose(PIL.Image.FLIP_LEFT_RIGHT).transpose(
PIL.Image.ROTATE_90)
if image_orientation == 6:
image = image.transpose(PIL.Image.ROTATE_270)
if image_orientation == 7:
image = image.transpose(PIL.Image.FLIP_TOP_BOTTOM).transpose(
PIL.Image.ROTATE_90)
if image_orientation == 8:
image = image.transpose(PIL.Image.ROTATE_90)
except:
pass
return image

librephotos/api/models.py

Lines 348 to 383 in b3e1e80

def _extract_date_time_from_exif(self):
date_format = "%Y:%m:%d %H:%M:%S"
timestamp_from_exif = None
with open(self.image_path, 'rb') as fimg:
exif = exifread.process_file(fimg, details=False)
serializable = dict(
[key, value.printable] for key, value in exif.items())
self.exif_json = serializable
if 'EXIF DateTimeOriginal' in exif.keys():
tst_str = exif['EXIF DateTimeOriginal'].values
try:
timestamp_from_exif = datetime.strptime(
tst_str, date_format).replace(tzinfo=pytz.utc)
except:
timestamp_from_exif = None
old_album_date = self._find_album_date()
if(self.exif_timestamp != timestamp_from_exif):
self.exif_timestamp = timestamp_from_exif
if old_album_date is not None:
old_album_date.photos.remove(self)
old_album_date.save()
album_date = None
if self.exif_timestamp:
album_date = get_or_create_album_date(date=self.exif_timestamp.date(), owner=self.owner)
album_date.photos.add(self)
else:
album_date = get_or_create_album_date(date=None, owner=self.owner)
album_date.photos.add(self)
album_date.save()
self.save()

librephotos/api/models.py

Lines 385 to 408 in b3e1e80

def _extract_gps_from_exif(self):
with open(self.image_path, 'rb') as fimg:
exif = exifread.process_file(fimg, details=False)
serializable = dict(
[key, value.printable] for key, value in exif.items())
self.exif_json = serializable
if 'GPS GPSLongitude' in exif.keys():
self.exif_gps_lon = util.convert_to_degrees(
exif['GPS GPSLongitude'].values)
# Check for correct positive/negative degrees
if exif['GPS GPSLongitudeRef'].values != 'E':
self.exif_gps_lon = -float(self.exif_gps_lon)
else:
self.exif_gps_lon = None
if 'GPS GPSLatitude' in exif.keys():
self.exif_gps_lat = util.convert_to_degrees(
exif['GPS GPSLatitude'].values)
# Check for correct positive/negative degrees
if exif['GPS GPSLatitudeRef'].values != 'N':
self.exif_gps_lat = -float(self.exif_gps_lat)
else:
self.exif_gps_lat = None
self.save()

@derneuere
Copy link
Member Author

Changed!

AnkurPrabhu pushed a commit to AnkurPrabhu/librephotos that referenced this issue Oct 22, 2023
…_yarn/axios-0.21.1

Bump axios from 0.18.1 to 0.21.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant