Created
May 7, 2013 09:58
-
-
Save KelSolaar/5531550 to your computer and use it in GitHub Desktop.
Nuke - Autocrop
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
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