25 lines
745 B
Python
25 lines
745 B
Python
import sys
|
|
from PIL import Image
|
|
|
|
def crop_image(x1, y1, x2, y2, input_path, output_path):
|
|
try:
|
|
with Image.open(input_path) as img:
|
|
cropped_img = img.crop((x1, y1, x2, y2))
|
|
cropped_img.save(output_path)
|
|
print(f"Bild erfolgreich gespeichert als {output_path}")
|
|
except Exception as e:
|
|
print(f"Fehler: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 7:
|
|
print("Verwendung: python crop_image.py x1 y1 x2 y2 input_path output_path")
|
|
sys.exit(1)
|
|
|
|
x1 = int(sys.argv[1])
|
|
y1 = int(sys.argv[2])
|
|
x2 = int(sys.argv[3])
|
|
y2 = int(sys.argv[4])
|
|
input_path = sys.argv[5]
|
|
output_path = sys.argv[6]
|
|
|
|
crop_image(x1, y1, x2, y2, input_path, output_path) |