Auto-Generate 128-Frame Knob Filmstrips for HISE
-
Hi everyone,
I’d like to share a Python script that saves a lot of time when creating knob filmstrips for HISE.
Instead of rotating a knob image manually frame by frame, this script:
Takes one knob image
Automatically detects the visible (non-transparent) area
Crops and centers it perfectly
Rotates it smoothly
Exports a 128-frame sprite sheet (no jitter, no wobble)Features
- True center rotation (no shaking)
- list itemAutomatic alpha-based cropping
- list item 128 frames (super smooth)
- list item Vertical or horizontal filmstrip
- list item Ready to use in HISE
- list item Huge time saver
Requirements :
pip install pillow numpyFull Python Code :
️from PIL import Image import numpy as np import os # === Settings === image_path = "PATH/TO/KNOB.png" output_image = "PATH/TO/KNOB_128fps.png" num_frames = 128 start_angle = 150 end_angle = -150 orientation = "vertical" # "vertical" or "horizontal" # === Load image === img = Image.open(image_path).convert("RGBA") w, h = img.size # === Detect non-transparent area === alpha = np.array(img.split()[-1]) ys, xs = np.nonzero(alpha > 0) x_min, x_max = xs.min(), xs.max() y_min, y_max = ys.min(), ys.max() # === Crop to real knob area === img = img.crop((x_min, y_min, x_max, y_max)) w, h = img.size # === Make square canvas for perfect rotation === side = max(w, h) square = Image.new("RGBA", (side, side), (0, 0, 0, 0)) offset = ((side - w) // 2, (side - h) // 2) square.paste(img, offset) img = square w = h = side # === Lock rotation center === cx, cy = w / 2, h / 2 print(f"Rotation center locked at ({cx}, {cy})") # === Create sprite sheet === if orientation == "horizontal": sprite = Image.new("RGBA", (w * num_frames, h), (0, 0, 0, 0)) else: sprite = Image.new("RGBA", (w, h * num_frames), (0, 0, 0, 0)) # === Generate frames === for i in range(num_frames): angle = start_angle + (end_angle - start_angle) * (i / (num_frames - 1)) rotated = img.rotate(angle, resample=Image.BICUBIC, center=(cx, cy)) if orientation == "horizontal": sprite.paste(rotated, (i * w, 0)) else: sprite.paste(rotated, (0, i * h)) sprite.save(output_image) print(f"Sprite generated successfully: {output_image}")Save the file with this name :
️generate_knob_sprite.pyMake sure the file extension is .py and not .txt.
Open Command Prompt / PowerShell & Run the script
️python .\generate_knob_sprite.pyGood luck