Package: convert-tif-to-png
TIF to PNG Image ConverterIntroductionThis 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.RequirementsPython 3.5+PIL (Pillow) libraryDevelopmentpoetryis used to manage dependencies and virtual environments.GitHub Actionsis used for CI/CD, with a trusted publishing connection to PyPi.InstallationInstall the convert-tif-to-png tool via pip:pipinstallconvert-tif-to-pngAlso, ensure you have the required Pillow library:pipinstallPillowUsageCommand Line OptionsOptionDescription--dirPath to directory containing TIF files to convert.--filePath to individual TIF file(s) to convert.--patternRegex pattern to name converted files, extracted from the original file name.--sizeResize images to one of the following sizes:original,4k,2k.--logLog output to file. Defaults to./.log.txtExamplesNote: You can use Python's-mflag to run a Module as a script. Module names use underscores instead of hyphens.To process a directory:python3-mconvert_tif_to_png--dir/path/to/directory--pattern'some-regex-pattern'--size4kTo process individual files:python3-mconvert_tif_to_png--file/path/to/file1.tif/path/to/file2.tif--pattern'some-regex-pattern'--size4kRegex PatternRegular expressions (regex) are patterns used to match and manipulate strings in text. UseRegExrto 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--patternoption 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).tifUse 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.pngNote that if there is a mismatch with the pattern, the original file name will be used.Integration: MacOS AutomatorPrerequisitesBefore integrating this script into MacOS Automator, make sure you have the following prerequisites installed and configured:pyenv: A Python version management tool, used to set the Python version for the script.Installation: Use Homebrew by runningbrew install pyenvin your terminal.Setting up: Addpyenv initto your shell to enable shims and autocompletion.See official documentation for more details.Python Path: You'll need the full path to your Python interpreter.Finding Python Path: Runwhich pythonorwhich python3in your terminal to get the full path.IntegrationTo integrate this script into macOS Automator for automated file processing:Open Automator and create a new "Folder Action."Set the "Folder Action receives files and folders added to" to your desired directory.Set "Pass input" to "as arguments."Add a "Run Shell Script" action.Enter the full path to your Python interpreter and script, along with any command line arguments, like so:/full/path/to/python3-mconvert_tif_to_png--size4k--pattern'some-regex-pattern'--file"$@"Make sure you replace/full/path/to/python3with 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.