Skip to content

Instantly share code, notes, and snippets.

@donspaulding
Created April 16, 2013 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donspaulding/5400329 to your computer and use it in GitHub Desktop.
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/
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