Skip to content

Instantly share code, notes, and snippets.

@KelSolaar
Created May 7, 2013 09:58
Show Gist options
  • Save KelSolaar/5531550 to your computer and use it in GitHub Desktop.
Save KelSolaar/5531550 to your computer and use it in GitHub Desktop.
Nuke - Autocrop
def getCropRectangle(node):
width, height = node.width(), node.height()
xMin = width
xMax = 0
yMin = height
yMax = 0
for x in range(width):
for y in range(height):
if node.sample("alpha", x, y) != 0:
xMin = min(x, xMin)
yMin = min(y, yMin)
xMax = max(x, xMax)
yMax = max(y, yMax)
return xMin, yMin, xMax, yMax
def setAutoCrop(node):
crop = nuke.nodes.Crop(box = " ".join(map(str, getCropRectangle(node))), reformat=True)
crop.setInput(0, node)
return True
for node in nuke.selectedNodes():
setAutoCrop(node)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment