Python PIL.ExifTags.TAGS Examples
The following are 12
code examples of PIL.ExifTags.TAGS().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PIL.ExifTags
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: demo_pytorch_CAM.py From places365 with MIT License | 6 votes |
def imreadRotate(fn): image=Image.open(fn) try: for orientation in ExifTags.TAGS.keys(): if ExifTags.TAGS[orientation]=='Orientation': break exif=dict(image._getexif().items()) if exif[orientation] == 3: image=image.rotate(180, expand=True) elif exif[orientation] == 6: image=image.rotate(270, expand=True) elif exif[orientation] == 8: image=image.rotate(90, expand=True) except (AttributeError, KeyError, IndexError): # cases: image don't have getexif print('dont rotate') pass return image
Example #2
Source File: utils.py From Disfactory with MIT License | 6 votes |
def _get_image_original_date(f_image): img = Image.open(f_image) exif_raw = img._getexif() if exif_raw is None: return None exif = {} for k, v in exif_raw.items(): if k in ExifTags.TAGS: exif[ExifTags.TAGS[k]] = v try: return datetime.strptime(exif["DateTimeOriginal"], "%Y:%m:%d %H:%M:%S") except: return None
Example #3
Source File: detect.py From yolo-tf with GNU Lesser General Public License v3.0 | 6 votes |
def read_image(path): image = Image.open(path) for key in ExifTags.TAGS.keys(): if ExifTags.TAGS[key] == 'Orientation': break try: exif = dict(image._getexif().items()) except AttributeError: return image if exif[key] == 3: image = image.rotate(180, expand=True) elif exif[key] == 6: image = image.rotate(270, expand=True) elif exif[key] == 8: image = image.rotate(90, expand=True) return image
Example #4
Source File: attacks.py From aletheia with MIT License | 5 votes |
def exif(filename): image = Image.open(filename) try: exif = { TAGS[k]: v for k, v in image._getexif().items() if k in TAGS } return exif except AttributeError: return {} # }}} # -- SAMPLE PAIR ATTACK -- # {{{ spa()
Example #5
Source File: smart-image-renamer.py From smart-image-renamer with GNU General Public License v2.0 | 5 votes |
def get_exif_data(img_file): """Read EXIF data from the image. img_file: Absolute path to the image file Returns: A dictionary containing EXIF data of the file Raises: NotAnImageFile if file is not an image InvalidExifData if EXIF can't be processed """ try: img = Image.open(img_file) except (OSError, IOError): raise NotAnImageFile try: # Use TAGS module to make EXIF data human readable exif_data = { TAGS[k]: v for k, v in img._getexif().items() if k in TAGS } except AttributeError: raise InvalidExifData # Add image format to EXIF exif_data['format'] = img.format return exif_data
Example #6
Source File: util.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def generate_file_icon(file_path): """ Generates a small and a big thumbnail of an image This will make it possible to preview the sent file :param file_path: The path to the image """ im = Image.open(file_path) # rotate according to EXIF tags try: exif = dict((ExifTags.TAGS[k], v) for k, v in im._getexif().items() if k in ExifTags.TAGS) angles = {3: 180, 6: 270, 8: 90} orientation = exif['Orientation'] if orientation in angles.keys(): im = im.rotate(angles[orientation], expand=True) except AttributeError: pass # no EXIF data available # Big image im.thumbnail((540, 540), Image.ANTIALIAS) imgByteArr = io.BytesIO() im.save(imgByteArr, format='JPEG2000') file_icon = imgByteArr.getvalue() # Small image #im.thumbnail((64, 64), Image.ANTIALIAS) #imgByteArr = io.BytesIO() #im.save(imgByteArr, format='JPEG2000') #small_file_icon = imgByteArr.getvalue() return file_icon
Example #7
Source File: photohandler.py From Raspberry-Pi-3-Cookbook-for-Python-Programmers-Third-Edition with MIT License | 5 votes |
def initExif(self,image): """gets any Exif data from the photo""" try: self.exif_info={ ExifTags.TAGS[x]:y for x,y in image._getexif().items() if x in ExifTags.TAGS } self.exifvalid=True except AttributeError: print ("Image has no Exif Tags") self.exifvalid=False
Example #8
Source File: photohandler_1stpart.py From Raspberry-Pi-3-Cookbook-for-Python-Programmers-Third-Edition with MIT License | 5 votes |
def initExif(self,image): """gets any Exif data from the photo""" try: self.exif_info={ ExifTags.TAGS[x]:y for x,y in image._getexif().items() if x in ExifTags.TAGS } self.exifvalid=True except AttributeError: print ("Image has no Exif Tags") self.exifvalid=False
Example #9
Source File: util.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def generate_file_icon(file_path): """ Generates a small and a big thumbnail of an image This will make it possible to preview the sent file :param file_path: The path to the image """ im = Image.open(file_path) # rotate according to EXIF tags try: exif = dict((ExifTags.TAGS[k], v) for k, v in im._getexif().items() if k in ExifTags.TAGS) angles = {3: 180, 6: 270, 8: 90} orientation = exif['Orientation'] if orientation in angles.keys(): im = im.rotate(angles[orientation], expand=True) except AttributeError: pass # no EXIF data available # Big image im.thumbnail((540, 540), Image.ANTIALIAS) imgByteArr = io.BytesIO() im.save(imgByteArr, format='JPEG2000') file_icon = imgByteArr.getvalue() # Small image #im.thumbnail((64, 64), Image.ANTIALIAS) #imgByteArr = io.BytesIO() #im.save(imgByteArr, format='JPEG2000') #small_file_icon = imgByteArr.getvalue() return file_icon
Example #10
Source File: image.py From ingestors with MIT License | 5 votes |
def extract_exif(self, img): if not hasattr(img, '_getexif'): return exif = img._getexif() if exif is None: return make, model = '', '' for num, value in exif.items(): try: tag = ExifTags.TAGS[num] except KeyError: log.warning("Unknown EXIF code: %s", num) continue if tag == 'DateTimeOriginal': self.update('created_at', self.parse_exif_date(value)) if tag == 'DateTime': self.update('date', self.parse_exif_date(value)) if tag == 'Make': make = value if tag == 'Model': model = value generator = ' '.join((make, model)) self.update('generator', generator.strip())
Example #11
Source File: util.py From opendrop with GNU General Public License v3.0 | 5 votes |
def generate_file_icon(file_path): """ Generates a small and a big thumbnail of an image This will make it possible to preview the sent file :param file_path: The path to the image """ im = Image.open(file_path) # rotate according to EXIF tags try: exif = dict((ExifTags.TAGS[k], v) for k, v in im._getexif().items() if k in ExifTags.TAGS) angles = {3: 180, 6: 270, 8: 90} orientation = exif['Orientation'] if orientation in angles.keys(): im = im.rotate(angles[orientation], expand=True) except (AttributeError, KeyError): pass # no EXIF data available # Big image im.thumbnail((540, 540), Image.ANTIALIAS) imgByteArr = io.BytesIO() im.save(imgByteArr, format='JPEG2000') file_icon = imgByteArr.getvalue() # Small image # im.thumbnail((64, 64), Image.ANTIALIAS) # imgByteArr = io.BytesIO() # im.save(imgByteArr, format='JPEG2000') # small_file_icon = imgByteArr.getvalue() return file_icon
Example #12
Source File: models.py From connect with MIT License | 5 votes |
def process_exif_data(self): """Extract EXIF data from the image and add it to the model""" # pylint: disable=protected-access # Re-open the image self.image.open() image_file = StringIO(self.image.read()) image_file.seek(0) # Open the image original = PILImage.open(image_file) # Find out if it is an image with EXIF data if hasattr(original, '_getexif'): exif = original._getexif() if exif: # Match the EXIF field codes to the tag name self.exif = { ExifTags.TAGS[code]: value for (code, value) in original._getexif().items() if code in ExifTags.TAGS } try: # Save the image self.save(process=False, update_fields=['exif']) except UnicodeDecodeError: # Oh well pass # Close out the file image_file.close()