Skip to main content

TIF to PNG Image Converter

Introduction

This Python script converts TIF images to PNG format. It allows for resizing the images to various predefined sizes (Original, 4K, 2K) and works either on a directory or individual files. It also allows for renaming the converted files based on a regex pattern extracted from the original file name.

Requirements

  • Python 3.5+
  • PIL (Pillow) library

Development

poetry is used to manage dependencies and virtual environments. GitHub Actions is used for CI/CD, with a trusted publishing connection to PyPi.

Installation

Install the convert-tif-to-png tool via pip:

pip install convert-tif-to-png

Also, ensure you have the required Pillow library:

pip install Pillow

Usage

Command Line Options

Option Description
--dir Path to directory containing TIF files to convert.
--file Path to individual TIF file(s) to convert.
--pattern Regex pattern to name converted files, extracted from the original file name.
--size Resize images to one of the following sizes: original, 4k, 2k.
--log Log output to file. Defaults to ./.log.txt

Examples

Note: You can use Python's -m flag to run a Module as a script. Module names use underscores instead of hyphens.

To process a directory:

python3 -m convert_tif_to_png --dir /path/to/directory --pattern 'some-regex-pattern' --size 4k

To process individual files:

python3 -m convert_tif_to_png --file /path/to/file1.tif /path/to/file2.tif --pattern 'some-regex-pattern' --size 4k

Regex Pattern

Regular expressions (regex) are patterns used to match and manipulate strings in text. Use RegExr to learn about, build, and test your patterns in a UI. ChatGPT is another great resource for learning Regex and building complex patterns with natural language.

The --pattern option renames converted files based on a regex pattern extracted from the original file name, excluding the file extension and preceding path information.

As an example, if you have the following files:

CANON1234.tif
CANON5678.tif
CANON8149-ENHANCED-NR.tif
CANON9322-ENHANCED-NR.tif
CANON9322-ENHANCED-NR (copy 1).tif

Use the following regex pattern to extract the file name CANON followed by a series of numbers:

--pattern 'CANON\d+'

This will result in the following file names:

CANON1234.png
CANON5678.png
CANON8149.png
CANON9322.png
CANON9322.png

Note that if there is a mismatch with the pattern, the original file name will be used.

Integration: MacOS Automator

Prerequisites

Before integrating this script into MacOS Automator, make sure you have the following prerequisites installed and configured:

  1. pyenv: A Python version management tool, used to set the Python version for the script.

  2. Python Path: You'll need the full path to your Python interpreter.

    • Finding Python Path: Run which python or which python3 in your terminal to get the full path.

Integration

To integrate this script into macOS Automator for automated file processing:

  1. Open Automator and create a new "Folder Action."
  2. Set the "Folder Action receives files and folders added to" to your desired directory.
  3. Set "Pass input" to "as arguments."
  4. Add a "Run Shell Script" action.
  5. Enter the full path to your Python interpreter and script, along with any command line arguments, like so:
/full/path/to/python3 -m convert_tif_to_png --size 4k --pattern 'some-regex-pattern' --file "$@"

Make sure you replace /full/path/to/python3 with the actual path on your system. The "$@" parameter in Automator references file(s) added to the folder.

Any new TIF files added to the specified folder will automatically be converted to PNG.

Release files for convert-tif-to-png 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for convert-tif-to-png 1.0.6
File Size Uploaded
convert_tif_to_png-1.0.6.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for convert-tif-to-png 1.0.6
File Interpreter ABI Platform
convert_tif_to_png-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / convert_tif_to_png-1.0.6.tar.gz

Download URL convert_tif_to_png-1.0.6.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
845640ab32fac570bacd7998e76ac2d6b1079f3c1fcb98a10ab1bec16d368351
BLAKE2b-256 checksum
How to use checksums
70bd24e43dcaaf52ab5ae97fa2a3acd544e175e1e818d508402497cf63a943a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / convert_tif_to_png-1.0.6-py3-none-any.whl

Download URL convert_tif_to_png-1.0.6-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57cdb1013c62a1974da55c1d4928cc3b41035d51f23061023705ce9a9acc9b08
BLAKE2b-256 checksum
How to use checksums
19b1287e271a2da32628f3947453cbd6de7d679d0aa041bd38459ee69d0c7aa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page