Skip to content

Instantly share code, notes, and snippets.

@tuxdna
Created February 27, 2019 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxdna/cc07f7711565e47994cf10871f01d7d4 to your computer and use it in GitHub Desktop.
Save tuxdna/cc07f7711565e47994cf10871f01d7d4 to your computer and use it in GitHub Desktop.
Python script to crop images
# find . -name "Screenshot*.png" -exec python3 crop-all.py "{}" \;
import sys
import os
import subprocess
top_left = (33, 213)
bot_right = (910, 780)
width = bot_right[0] - top_left[0]
height = bot_right[1] - top_left[1]
print(sys.argv)
print(width, height)
input_image = sys.argv[1]
# 713x470+5+3
x_offset, y_offset = top_left
crop_size = "%dx%d+%d+%d" % (width, height, x_offset, y_offset)
output_file = os.path.join("notes", input_image + ".jpg")
a = subprocess.run(["convert", input_image, "-crop", crop_size, output_file])
print(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment