24 lines
565 B
Python
Executable File
24 lines
565 B
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf8 -*-
|
|
|
|
from PIL import Image
|
|
import sys
|
|
|
|
# check if filename is present
|
|
if len(sys.argv) == 1:
|
|
sys.exit("error: no filename spcified")
|
|
f = sys.argv[1]
|
|
|
|
# open, crop and overwrite image
|
|
print(f"cropping file {f} … ", end='')
|
|
with Image.open(f) as i:
|
|
# do nothing if size and bbox are equivalent
|
|
bbox = i.getbbox()
|
|
if bbox[0] == 0 and bbox[1] == 0 and bbox[2] == i.size[0] and bbox[3] == i.size[1]:
|
|
print("nothing to do")
|
|
sys.exit(0)
|
|
|
|
i.crop(i.getbbox()).save(f)
|
|
|
|
print("successful")
|