Last active
November 19, 2025 05:16
-
-
Save mq1n/c46c0ae4de2fb72897ba13fa22826ab0 to your computer and use it in GitHub Desktop.
Topaz Photo AI CLI Sample with Python Automated Script & DDS Support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os, sys, subprocess | |
| try: | |
| from wand.image import Image | |
| except ImportError: | |
| os.system('python -m pip install wand') | |
| from wand.image import Image | |
| def main(args): | |
| if len(args) < 1: | |
| print('Usage: upscaler.py <input_image> [output_image]') | |
| return 1 | |
| input_image = args[0] | |
| output_image = args[1] if len(args) > 1 else None | |
| temp_image = None | |
| if not os.path.exists(input_image): | |
| print('Input image not found:', input_image) | |
| return 1 | |
| upscalerProc = "C:\\Program Files\\Topaz Labs LLC\\Topaz Photo AI\\tpai.exe" | |
| if not os.path.exists(upscalerProc): | |
| print('Upscaler not found:', upscalerProc) | |
| return 1 | |
| if output_image is None: | |
| output_image = input_image | |
| temp_image = os.path.splitext(input_image)[0] + '_upscaled_temp.tga' | |
| if not os.path.isabs(output_image): | |
| output_image = os.path.abspath(output_image) | |
| temp_image = os.path.abspath(temp_image) | |
| if os.path.exists(output_image) and not os.path.samefile(input_image, output_image): | |
| os.remove(output_image) | |
| if os.path.exists(temp_image): | |
| os.remove(temp_image) | |
| print('Upscaling', input_image, 'to', output_image) | |
| # Convert the image | |
| with Image(filename=input_image) as img: | |
| img.compression = "no" | |
| img.save(filename=temp_image) | |
| # Upscale the image | |
| upscaleCommand = f'"{upscalerProc}" --overwrite --upscale scale=4 height=2048 width=2048 minor_denoise=100 minor_deblur=100 model="High Fidelity V2" --sharpen strength=100 --denoise strength=100 minor_deblur=100 original_detail=100 --quality 100 --compression 10 --tiff-compression "lzw" "{temp_image}"' | |
| print('Running:', upscaleCommand) | |
| try: | |
| subprocess.run(upscaleCommand, shell=True, check=True) | |
| except subprocess.CalledProcessError as e: | |
| print('Upscaler failed:', e) | |
| return 1 | |
| if os.path.exists(output_image): | |
| os.remove(output_image) | |
| # Convert the image back | |
| with Image(filename=temp_image) as img: | |
| img.compression = "dxt3" | |
| img.save(filename=output_image) | |
| if temp_image is not None and os.path.exists(temp_image): | |
| os.remove(temp_image) | |
| print('Done, upscaled image saved to', output_image) | |
| return 0 | |
| if __name__ == '__main__': | |
| sys.exit(main(sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment