Skip to main content

Rename image files according to exif tags

Project description

Travis-CI Build Status AppVeyor Build status Documentation Status

pyimgren

A python module to rename images according to their exif tags.

Current status

This package package is distributed in PyPI since version 0.1.0. It can be used by end users, but should be considered at beta quality because it still lacks extensive testing. Its full source is available from GitHUB.

Goals

Digital cameras name their pictures in a sequential manner. When you want to put pictures from several cameras in the same folder, they will be sorted by camera instead of by picture date and time.

Even if we can find here and there programs that allow for batch renaming of such pictures, I could not find a portable Python module for that. So the goals of this project are:

  • few dependencies: a Python 3 (tested for >= 3.3)
  • few additional module requirements: only piexif is required at installation time
  • portability: this is a pure Python package and is tested with Travis-CI (linux) and AppVeyor (Windows) for versions 3.3 to 3.6 (3.7 for AppVeyor only).

Usage:

As a Python module

The pyimgren package contains one single class Renamer with two public methods: rename to rename picture files according to their exif date, and back to rename them back to their original names.

A Renamer is used to rename image names provided by a camera (commonly IMGxxxxx.JPG or DSCFyyyy.JPG into a name based on the time when the photography had been taken (as smartphones do). That time is extracted from the exif tag of the picture. No rename occurs if the picture contains no exif time..

A file named names.log is created in the folder to store the new names and the original ones, in order to be able to rename them back.

You create a Renamer with:

renamer = Renamer(folder, src_mask = "DSCF*.jpg",
                dst_mask = "%Y%m%d_%H%M%S",
                ext_mask = ".jpg",
                ref_file = "names.log",
                debug = False,
                dummy = False)

Parameters:

  • folder: the default folder where pictures will be renamed
  • src_mask: a pattern to select the files to be renamed (default "DSCF*.jpg")
  • dst_mask: a format containing strftime formatting directives, that will be used for the new name of a picture (default "%Y%m%d_%H%M%S")
  • ext_mask: the extension of the new name (default ".jpg")
  • ref_file: the name of a file that will remember the old names (default "names.log")
  • debug : a boolean flag that will cause a line to be printed for each rename when true (default False)
  • dummy : a boolean flag that will cause a "dry run", meaning that the folder will be scanned, and debug info eventually printed but no file will be renamed (default False)

Typical use:

from pyimgren import Renamer
...
conv = Renamer(path)
conv.rename()    # to convert to "date" names
...
conv.back()      # if you want to revert to original names

As a script

The pip installation install a pyimgren script (pyimgren.exe on Windows) in the Scripts directory. It can then be directly used (provided the Script directory be in the path) with the following syntax:

usage: pyimgren [-h] [-v] [-b] [-s SRC_MASK] [-d DST_MASK] [-e EXT_MASK]
                [-r REF_FILE] [-D] [-X]
                folder [files [files ...]]

Rename pictures according to their exif timestamp

positional arguments:
  folder                folder containing files to rename
  files                 files of sub folders to process (optional)

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -b, --back            restore original names
  -s SRC_MASK, --src_mask SRC_MASK
                        pattern to select the files to rename
  -d DST_MASK, --dst_mask DST_MASK
                        format for the new file name
  -e EXT_MASK, --ext EXT_MASK
                        extension for the new file name
  -r REF_FILE, --ref_file REF_FILE
                        a file to remember the old names
  -D, --debug           print a line per rename
  -X, --dry_run         process normally except no rename occurs

As a module

It can be use as a Python module, which allows to use it in Windows even if the Scripts directory is not in the path thanks to the py launcher with same syntax as the script:

usage: python -m pyimgren [-h] [-v] [-b] [-s SRC_MASK] [-d DST_MASK]
                [-e EXT_MASK] [-r REF_FILE] [-D] [-X]
                folder [files [files ...]]

or when using the Windows launcher py -m pyimgren ...

Installing

End user installation

With pip: pip install pyimgren.

Developper installation

If you want to contribute or integrate pyimgren in your own code, you should get a copy of the full tree from GitHUB:

git clone https://github.com/s-ball/pyimgren [your_working_copy_folder]

Running the tests

As the project intends to be PyPI compatible, you can simply run tests from the main folder with:

python setup.py test

The integration tests depend on pyfakefs, which is automatically intalled from PyPI when you run python setup.py test. But it is not require for running pyimgren, nor installed by pip install pyimgren.

Contributing

As this project is developped on my free time, I cannot guarantee very fast feedbacks. Anyway, I shall be glad to receive issues or pull requests on GitHUB.

Versioning

This project uses a standard Major.Minor.Patch versioning pattern. Inside a major version, public API stability is expected (at least after 1.0.0 version will be published).

License

This project is licensed under the MIT License - see the LICENSE.txt file for details

Acknowledgments

  • The hard job of exif data processing was already done in piexif
  • The excellent pyfakefs, allows integration tests to run on a fake file system

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyimgren-0.4.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyimgren-0.4.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file pyimgren-0.4.1.tar.gz.

File metadata

  • Download URL: pyimgren-0.4.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for pyimgren-0.4.1.tar.gz
Algorithm Hash digest
SHA256 4e6a8a24a01528e0081587f59022ce30f42de0a82179eb640adc01b073fc28dc
MD5 5f874b2e45365430ada5088e85158ab6
BLAKE2b-256 2bcfaa2646f5031ea3fd4ea5f564f1b157ed69636283e7df8047491a41f0f505

See more details on using hashes here.

File details

Details for the file pyimgren-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: pyimgren-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for pyimgren-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cec4bf39fbdafe606431f8e2459ae754e939e6c6839faae2609ebfa1e6f8297
MD5 4e3f3f97aa7ef9e8eb47a7bcac3e5d8b
BLAKE2b-256 fef65f384a575cd03fef17f7c6659b1c19436c97ea91e61ce6d1b1bf463bdb54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page