Created
April 16, 2013 22:49
-
-
Save donspaulding/5400329 to your computer and use it in GitHub Desktop.
A pretty decent way to wrap the libtiff command-line tools from python. Pretty decent, that is, until you remember that `sh` exists and works even better... http://amoffat.github.io/sh/
This file contains 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 subprocess | |
def create_libtiff_tool(command_name): | |
try: | |
help_str = subprocess.check_output( | |
command_name, | |
stderr=subprocess.STDOUT | |
) | |
except subprocess.CalledProcessError, e: | |
help_str = e.output | |
def libtiff_tool_wrapper(*args): | |
return subprocess.check_call([command_name] + list(args)) | |
libtiff_tool_wrapper.__doc__ = help_str | |
return libtiff_tool_wrapper | |
libtiff_tools = [ | |
'tiff2bw', | |
'tiff2pdf', | |
'tiff2rgba', | |
'tiffcp', | |
'tiffdiff', | |
'tiffdump', | |
'tiffinfo', | |
'tiffset', | |
'tiffutil', | |
'tiff2icns', | |
'tiff2ps', | |
'tiffcmp', | |
'tiffcrop', | |
'tiffdither', | |
'tifficc', | |
'tiffmedian', | |
'tiffsplit' | |
] | |
G = globals() | |
for command in libtiff_tools: | |
G[command] = create_libtiff_tool(command) | |
__all__ = libtiff_tools |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment