Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions images/squarify.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
from PIL import Image


if __name__ == '__main__':
if __name__ == "__main__":
try:
path = Path(sys.argv[1])
except IndexError:
sys.exit(f"Usage: {__file__} IMAGE_PATH")

im = Image.open(path)

out_path = path.with_suffix(".square" + path.suffix)
assert out_path != path

if im.width == im.height:
print(path)
elif im.width > im.height:
left = (im.width - im.height) / 2
upper = 0
right = im.width - (im.width - im.height) / 2
lower = im.height

crop_im = im.crop((left, upper, right, lower))
crop_im.save(out_path)
print(out_path)
Expand All @@ -36,10 +36,9 @@
upper = (im.height - im.width) / 2
right = im.width
lower = im.height - (im.height - im.width) / 2

crop_im = im.crop((left, upper, right, lower))
crop_im.save(out_path)
print(out_path)


# main()

# main()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ python-multipart==0.0.6
# via asgi-csrf
pyyaml==6.0.1
# via datasette
ruff==0.9.3
ruff==0.9.4
# via -r requirements.in
s3transfer==0.10.2
# via boto3
Expand Down