Python get image exif

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Easy to use Python module to extract Exif metadata from digital image files.

License

ianare/exif-py

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.rst

Easy to use Python module to extract Exif metadata from digital image files.

Supported formats: TIFF, JPEG, PNG, Webp, HEIC

EXIF.py is tested and officially supported on Python 3.5 to 3.11

Starting with version 3.0.0 , Python2 compatibility is dropped completely (syntax errors due to type hinting).

The recommended process is to install the PyPI package, as it allows easily staying up to date:

EXIF.py is mature software and strives for stability.

After cloning the repo, use the provided Makefile:

Which will install a virtual environment and install development dependencies.

EXIF.py image1.jpg EXIF.py -dc image1.jpg image2.tiff find ~/Pictures -name "*.jpg" -o -name "*.tiff" | xargs EXIF.py

Show command line options:

import exifread # Open image file for reading (must be in binary mode) with open(file_path, "rb") as file_handle: # Return Exif tags tags = exifread.process_file(file_handle)

Note: To use this library in your project as a Git submodule, you should:

Returned tags will be a dictionary mapping names of Exif tags to their values in the file named by file_path . You can process the tags as you wish. In particular, you can iterate through all the tags with:

for tag in tags.keys(): if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'): print "Key: %s, value %s" % (tag, tags[tag])

An if statement is used to avoid printing out a few of the tags that tend to be long or boring.

The tags dictionary will include keys for all of the usual Exif tags, and will also include keys for Makernotes used by some cameras, for which we have a good specification.

Note that the dictionary keys are the IFD name followed by the tag name. For example:

'EXIF DateTimeOriginal', 'Image Orientation', 'MakerNote FocusMode'

Tags are divided into these main categories:

  • Image : information related to the main image (IFD0 of the Exif data).
  • Thumbnail : information related to the thumbnail image, if present (IFD1 of the Exif data).
  • EXIF : Exif information (sub-IFD).
  • GPS : GPS information (sub-IFD).
  • Interoperability : Interoperability information (sub-IFD).
  • MakerNote : Manufacturer specific information. There are no official published references for these tags.

These options can be used both in command line mode and within a script.

Don’t process makernote tags, don’t extract the thumbnail image (if any).

Pass the -q or —quick command line arguments, or as:

tags = exifread.process_file(file_handle, details=False)

To process makernotes only, without extracting the thumbnail image (if any):

tags = exifread.process_file(file_handle, details=True, extract_thumbnail=False)

To extract the thumbnail image (if any), without processing makernotes:

tags = exifread.process_file(file_handle, details=False, extract_thumbnail=True)

To stop processing the file after a specified tag is retrieved.

Pass the -t TAG or —stop-tag TAG argument, or as:

tags = exifread.process_file(file_handle, stop_tag='TAG')

where TAG is a valid tag name, ex ‘DateTimeOriginal’ .

The two above options are useful to speed up processing of large numbers of files.

Return an error on invalid tags instead of silently ignoring.

Pass the -s or —strict argument, or as:

tags = exifread.process_file(file_handle, strict=True)

This example shows how to use the library to correct the orientation of an image (using Pillow for the transformation) before e.g. displaying it.

import exifread from PIL import Image import logging def _read_img_and_correct_exif_orientation(path): im = Image.open(path) tags = <> with open(path, "rb") as file_handle: tags = exifread.process_file(file_handle, details=False) if "Image Orientation" in tags.keys(): orientation = tags["Image Orientation"] logging.basicConfig(level=logging.DEBUG) logging.debug("Orientation: %s (%s)", orientation, orientation.values) val = orientation.values if 2 in val: val += [4, 3] if 5 in val: val += [4, 6] if 7 in val: val += [4, 8] if 3 in val: logging.debug("Rotating by 180 degrees.") im = im.transpose(Image.ROTATE_180) if 4 in val: logging.debug("Mirroring horizontally.") im = im.transpose(Image.FLIP_TOP_BOTTOM) if 6 in val: logging.debug("Rotating by 270 degrees.") im = im.transpose(Image.ROTATE_270) if 8 in val: logging.debug("Rotating by 90 degrees.") im = im.transpose(Image.ROTATE_90) return im

Copyright © 2002-2007 Gene Cash

Copyright © 2007-2023 Ianaré Sévi and contributors

A huge thanks to all the contributors over the years!

Originally written by Gene Cash & Thierry Bousch.

Available as open source under the terms of the BSD-3-Clause license.

See LICENSE.txt file for details.

About

Easy to use Python module to extract Exif metadata from digital image files.

Источник

[exif] Package¶

Read and modify image EXIF metadata using Python without any third-party software dependencies. For example, batch process image metadata using a Python script.

I developed this package in 2018 as a hobby; however, I no longer have the same bandwidth to work on this project. As always, contributions and bug fixes are welcome and appreciated. If this package does not suit your needs in its current form, I encourage you to investigate alternative packages such as piexif, Pillow, or the like.

Quick Start¶

Open an image with EXIF metadata using the Python open() built-in function. Ensure the binary mode flag is set. Pass this image file object into the exif.Image class:

>>> from exif import Image >>> with open('grand_canyon.jpg', 'rb') as image_file: . my_image = Image(image_file) . >>> my_image.has_exif True 

List EXIF attributes using the list_all() method:

>>> my_image.list_all() ['_exif_ifd_pointer', '_gps_ifd_pointer', 'aperture_value', 'brightness_value', 'color_space', 'components_configuration', 'compression', 'datetime', 'datetime_digitized', 'datetime_original', 'exif_version', 'exposure_bias_value', 'exposure_mode', 'exposure_program', 'exposure_time', 'f_number', 'flash', 'flashpix_version', 'focal_length', 'focal_length_in_35mm_film', 'gps_altitude', 'gps_altitude_ref', 'gps_datestamp', 'gps_dest_bearing', 'gps_dest_bearing_ref', 'gps_horizontal_positioning_error', 'gps_img_direction', 'gps_img_direction_ref', 'gps_latitude', 'gps_latitude_ref', 'gps_longitude', 'gps_longitude_ref', 'gps_speed', 'gps_speed_ref', 'gps_timestamp', 'jpeg_interchange_format', 'jpeg_interchange_format_length', 'lens_make', 'lens_model', 'lens_specification', 'make', 'maker_note', 'metering_mode', 'model', 'orientation', 'photographic_sensitivity', 'pixel_x_dimension', 'pixel_y_dimension', 'resolution_unit', 'scene_capture_type', 'scene_type', 'sensing_method', 'shutter_speed_value', 'software', 'subject_area', 'subsec_time_digitized', 'subsec_time_original', 'white_balance', 'x_resolution', 'y_and_c_positioning', 'y_resolution'] 

Access EXIF metadata tags using Python attribute notation:

>>> # Read tags with Python "get" notation. >>> my_image.gps_latitude (36.0, 3.0, 11.08) >>> my_image.gps_longitude (112.0, 5.0, 4.18) >>> my_image.model 'iPhone 7' >>> >>> # Modify tags with Python "set" notation. >>> my_image.make = "Python" >>> >>> # Delete tags with Python "del" notation. >>> del my_image.gps_latitude >>> del my_image.gps_longitude >>> >>> # Add new tags with Python "set" notation. >>> from exif import LightSource >>> my_image.light_source = LightSource.DAYLIGHT 

Write the image with modified EXIF metadata to an image file using open() in binary write mode:

>>> with open('modified_image.jpg', 'wb') as new_image_file: . new_image_file.write(my_image.get_file()) . 

Refer to the usage page for information and examples of alternative ways to access EXIF tags (e.g. with index/item syntax or with methods).

© Copyright 2021, Tyler N. Thieding Revision f1530fc1 .

Versions latest stable Downloads pdf html epub On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.

Источник

ExifRead 3.0.0

Easy to use Python module to extract Exif metadata from digital image files.

Supported formats: TIFF, JPEG, PNG, Webp, HEIC

Compatibility

EXIF.py is tested and officially supported on Python 3.5 to 3.10

Starting with version 3.0.0 , Python2 compatibility is dropped completely (syntax errors due to type hinting).

Installation

Stable Version

The recommended process is to install the PyPI package, as it allows easily staying up to date:

EXIF.py is mature software and strives for stability.

Development Version

After cloning the repo, use the provided Makefile:

Which will install a virtual environment and install development dependencies.

Usage

Command line

EXIF.py image1.jpg EXIF.py -dc image1.jpg image2.tiff find ~/Pictures -name "*.jpg" -o -name "*.tiff" | xargs EXIF.py

Show command line options:

Python Script

Note: To use this library in your project as a Git submodule, you should:

Returned tags will be a dictionary mapping names of Exif tags to their values in the file named by path_name. You can process the tags as you wish. In particular, you can iterate through all the tags with:

  An if statement is used to avoid printing out a few of the tags that tend to be long or boring.

The tags dictionary will include keys for all of the usual Exif tags, and will also include keys for Makernotes used by some cameras, for which we have a good specification.

Note that the dictionary keys are the IFD name followed by the tag name. For example:

'EXIF DateTimeOriginal', 'Image Orientation', 'MakerNote FocusMode'

Tag Descriptions

Tags are divided into these main categories:

  • Image : information related to the main image (IFD0 of the Exif data).
  • Thumbnail : information related to the thumbnail image, if present (IFD1 of the Exif data).
  • EXIF : Exif information (sub-IFD).
  • GPS : GPS information (sub-IFD).
  • Interoperability : Interoperability information (sub-IFD).
  • MakerNote : Manufacturer specific information. There are no official published references for these tags.

Processing Options

These options can be used both in command line mode and within a script.

Faster Processing

Don’t process makernote tags, don’t extract the thumbnail image (if any).

Pass the -q or —quick command line arguments, or as:

Stop at a Given Tag

To stop processing the file after a specified tag is retrieved.

Pass the -t TAG or —stop-tag TAG argument, or as:

where TAG is a valid tag name, ex 'DateTimeOriginal' .

The two above options are useful to speed up processing of large numbers of files.

Strict Processing

Return an error on invalid tags instead of silently ignoring.

Pass the -s or —strict argument, or as:

Usage Example

This example shows how to use the library to correct the orientation of an image (using Pillow for the transformation) before e.g. displaying it.

Credit

A huge thanks to all the contributors over the years!

Originally written by Gene Cash & Thierry Bousch.

Источник

Читайте также:  Php проверка русского имени
Оцените статью