Skip to content

Commit

Permalink
Add simple script to convert some images
Browse files Browse the repository at this point in the history
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
chriscoffee committed Jun 26, 2023
1 parent c3f8db5 commit dfd125b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.envrc
.direnv/
.direnv/
.DS_Store
50 changes: 50 additions & 0 deletions convert-speaker-images/convert-speakers-images.py
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()
1 change: 1 addition & 0 deletions convert-speaker-images/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pillow=9.5.0

0 comments on commit dfd125b

Please sign in to comment.