-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple script to convert some images
I couldn't be arsed faffing around with imagetragick and this serves a purpose somewhat. It's not supposed to look good or be optimal so don't judge.
- Loading branch information
1 parent
c3f8db5
commit dfd125b
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.envrc | ||
.direnv/ | ||
.direnv/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Badly converts an image and resizes it | ||
Written whilst trying to look after a child. | ||
I'm not handling all the cases I should because I simply can't be bothered | ||
""" | ||
import glob | ||
import os | ||
|
||
from PIL import Image | ||
|
||
size = 500, 500 | ||
|
||
def get_files(types=['*.jpg', '*.jpeg']): | ||
""" | ||
""" | ||
|
||
files = [] | ||
for e in types: | ||
files += glob.glob('./'+e) | ||
|
||
return files | ||
|
||
def convert_images(): | ||
""" | ||
""" | ||
|
||
for i in get_files(): | ||
try: | ||
im = Image.open(i) | ||
file_name, _ = os.path.splitext(i) | ||
im.thumbnail(size, Image.Resampling.LANCZOS) | ||
im.save('{}.png'.format(file_name.lower()), optimize=True) | ||
delete_stuff(i) | ||
except (ValueError, OSError) as e: | ||
print("yeah mate, you can't convert that image: %s" % e) | ||
|
||
def delete_stuff(file): | ||
""" | ||
""" | ||
|
||
try: | ||
os.remove(file) | ||
except OSError as e: | ||
print("can't find %s to delete: %s" % (e.filename, e.strerror)) | ||
|
||
if __name__ == '__main__': | ||
convert_images() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Pillow=9.5.0 |