Python Image Reduction


One of the problems I have is that I pic from my phone and then bluetooth to my pi.
No problem right? Well, yes. My phone does not allow me to reduce the image size to something I would use on the website.. even like 1024x768. Now I know high res pics are all the rage, but if I am just snapping off a note or drawing, I do not need anything near the minimum of 2160x2160.

The fix

Reference: Resizing an image (the python part)
Initially, I was pulling each one up in GIMP, resizing, export to new file.. totally yucky, time consuming and prone to error.
Using the tip in the linked article, I created a simply python script called
What I added to the sample was to create a new file to keep the original file in tact... simply by injecting _500 into the file name and reassembling it.
(Note, you will have to make executable either by chmod -x or chmod 755 else run python filename.jpg)

Usage: imagefile.jpg
This will create a new image called imagefile_500.jpg in the same directory with a width of 500px x automatic height adjustment.
Interestingly, for some reason, python wants to 'list' everything... I know there is probably a work-around but did not have time to reasearch. This was a problem with the incoming file name as well as the rebuilt file name. Thus the character replacement in the code. It basically removes the [' .... '] list wrapper chars.

The Python Code

Hope it helps.