Skip to content

Instantly share code, notes, and snippets.

@DLohn
Last active February 29, 2024 22:57
Show Gist options
  • Save DLohn/3d613976e2d19940f6473045fa3900b0 to your computer and use it in GitHub Desktop.
Save DLohn/3d613976e2d19940f6473045fa3900b0 to your computer and use it in GitHub Desktop.

Revisions

  1. DLohn revised this gist Feb 29, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion resize.py
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@
    else:
    new_size = (int(resize_to * (im.width/im.height)), resize_to)

    im_resized = im.resize((resize_to, resize_to))
    im_resized = im.resize(new_size)
    im_resized.save(full_path)
  2. DLohn created this gist Oct 25, 2023.
    22 changes: 22 additions & 0 deletions resize.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import sys
    import os
    from PIL import Image

    resize_to = 384

    target_dir = sys.argv[1]

    for file in os.listdir(target_dir):
    full_path = os.path.join(target_dir, file)
    try:
    im = Image.open(full_path)
    except:
    continue

    if im.width > im.height:
    new_size = (resize_to, int(resize_to * (im.height/im.width)))
    else:
    new_size = (int(resize_to * (im.width/im.height)), resize_to)

    im_resized = im.resize((resize_to, resize_to))
    im_resized.save(full_path)