Skip to content

Instantly share code, notes, and snippets.

@PeterDrakeNichols
Last active June 28, 2023 20:52
Show Gist options
  • Save PeterDrakeNichols/51f70013ae41b53223199995e63ca0de to your computer and use it in GitHub Desktop.
Save PeterDrakeNichols/51f70013ae41b53223199995e63ca0de to your computer and use it in GitHub Desktop.
Krita script to change filled shape to an outline that is easily refillable. Meant to make fixing animation spacing easier with the onion skin docker.
from krita import *
#A script to cut out the center of a filled shape so that you can see spacing better with the onion skin docker.
#Go to the frame and layer you want run the script and your left with an outline that you can see properly in the onion skin
#Just fill it back up when your done with the bucket tool
##------IMPORTANT!!!!!--------## Make sure onion skin opacity is less than 95% ish
#TIP: when refilling set your bucket tool to grow by 1px ish to get rid of any artifacts
#To add it to your project just go to tools -> scripts -> ten scripts-> click the elipse next to the hot key you want
#-> navigate to the script and your done!
def unfill_layer( stroke_weight = 5 ):
doc=Krita.instance().activeDocument()
if doc:
node=doc.activeNode()
else:
return
x,y,w,h = node.bounds().left(), node.bounds().top(), node.bounds().width(), node.bounds().height()
pixels=node.projectionPixelData(x,y,w,h)
rgba = 0
pixelBytes=[]
for i in range(w*h):
if pixels[rgba + 3] > int(250).to_bytes(1,'big'):
pixelBytes.append(255)
else:
pixelBytes.append(0)
rgba+=4
selection = Selection()
selection.setPixelData(QByteArray(bytes(pixelBytes)),x,y,w,h)
for i in range(stroke_weight):
selection.erode()
doc.setSelection(selection)
selection.cut(node)
doc.setSelection(Selection().clear())
doc.refreshProjection()
stroke = 5 #<----------Changes width of left over outline
unfill_layer(stroke_weight = stroke)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment