Code Monkey home page Code Monkey logo

Comments (2)

derneuere avatar derneuere commented on June 15, 2024

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()

from librephotos.

derneuere avatar derneuere commented on June 15, 2024

Changed!

from librephotos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.