Last active
September 29, 2021 22:00
-
-
Save SleepyBrett/9a15a3a5cb453dde29cd44d450575601 to your computer and use it in GitHub Desktop.
Simple python script using imagemagick that cuts regular rects out of a larger image
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
import sys | |
from wand.image import Image | |
if __name__ == "__main__": | |
sourceImageName = sys.argv[1] | |
outputNamePattern = "%d-%d-%s" | |
# how many pixel into the image should we start cutting | |
siStartX = 6 | |
siStartY = 6 | |
# cutter size | |
siCropW = 242 | |
siCropH = 242 | |
# gutter sizes (number of pixels to skip after the last cut to get to the new cut, do not include image h/w) | |
siGutterW = 16 | |
siGutterH = 16 | |
# number of rows/cols | |
siRows = 3 | |
siCols = 3 | |
for r in range(siRows): | |
for c in range(siCols): | |
x = siStartX + (c * (siCropW + siGutterW)) | |
y = siStartY + (r * (siCropH + siGutterH)) | |
fn = outputNamePattern % (r, c, sourceImageName) | |
print("Cropping col:%d x:%d x row:%d y:%d" % (c,x,r,y)) | |
outputImage = Image(filename = sourceImageName) | |
outputImage.crop(x, y, width=siCropW, height=siCropH) | |
outputImage.save(filename=fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment