If you don't need to work with HEIF, you can omit them, the code will work for the rest of image formats supported by PIL. These two lines from pillow_heif import register_heif_openerĪre required only if you want to have support of HEIF format, that is configured by default on modern Apple devices (.HEIC file extension). Also note that GPS tags have another tag-to-int encoding dictionary. In order to access other useful tags, such as ShutterSpeedValue, ApertureValue, ISOSpeedRatings, WhiteBalance, DateTimeOriginal, DateTimeDigitized, ExposureBiasValue, FocalLength, ExifImageWidth, ExifImageHeight, etc, you need to get an IFD called Exif. Make, Model, DateTime, Orientation, Software. Only some of useful tags are available on the root level of Exif now (e.g. ![]() The modern way of doing it: from PIL import Imageįrom PIL.ExifTags import TAGS, GPSTAGS, IFDįrom pillow_heif import register_heif_opener # HEIF support All other answers became slightly outdated, showing only few tags (around 14). Starting version 8.2.0 API of PIL changed slightly, hiding most of tags a bit deeper into methods of Exif. Lon = nvert_to_degress(gps_longitude)ĭate_and_time = self.exif_data ![]() Gps_longitude_ref = self.get_if_exist(gps_info, 'GPSLongitudeRef') Gps_longitude = self.get_if_exist(gps_info, 'GPSLongitude') Gps_latitude_ref = self.get_if_exist(gps_info, 'GPSLatitudeRef') Gps_latitude = self.get_if_exist(gps_info, "GPSLatitude") Provided exif_data (obtained through get_exif_data above)""" """Returns the latitude and longitude, if available, from the """Returns a dictionary from the exif data of an PIL Image item. Stored in the EXIF to degress in float format""" """Helper function to convert the GPS coordinates Tested with Python 3.8.8 and Pillow=8.1.0.įrom PIL import ImageDraw, ImageFont, ImageEnhance ![]() The keys are 16-bit integers that can be mapped to their string names using the ExifTags.TAGS module. The instance can be passed as an exif argument to include any changesĪs stated, you can iterate over the key-value pairs of the Exif instance like a regular dictionary. Values canīe retrieved and set like a dictionary. Getexif() has been added, which returns an Exif instance. ![]() For Python3.x and starting Pillow=6.0.0, Image objects now provide a "public"/official getexif() method that returns a instance or None if the image has no EXIF data.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |