r/Python • u/[deleted] • Mar 24 '21
Discussion Python made me look like a WIZARD
Today in work a request comes in for 745 headshots that need to be processed to fit 150x150px for an external platform. One team says it'll take them at least a week to do, the other team says they don't want it as it'll take even longer.
"They need them all black and white! It'll take some time to convert them! They're not even all the same size! UGH this just can't be done in the 2 days they've requested this!!!"
12 lines of code, the Pillow library and exactly 8.856 seconds of running said code... It was done. Panic over. Client happy.
I work in a design team but I'm a job coordinator (so I sort the jobs and make sure the right designers get them). They were amazed it was done so quickly without using Photoshop.
They asked how. I gave them the answer.
Python baby 😎
EDIT
For those wanting to know the code, here it is:
from PIL import Image
import os
for f in os.listdir('Input'):
if f.endswith('.jpg'):
im = Image.new('RGB', (150, 150), (255,255,255))
im2 = Image.open('Input/{}'.format(f))
im2 = im2.convert("L")
width, height = im2.size
im.paste(im2, (int((150 - width) / 2), 0))
fn, fext = os.path.splitext(f)
im.save('Output/{}.jpg'.format(fn))The images given were either 150x150 already (but in colour) or 120x150. So had to cover all bases with this. If it could be made more efficient, let me know!
1
u/[deleted] Mar 26 '21
But we aren't. That is just a cold hard fact. In the late 19th and 20th century we automated much of the manual labor. That work went away. We did get lucky in that many of those workers transitioned to factory work and were employed. We are now automating much of the intellectual work that was traditionally done by educated people. This work can also move at a moment's notice across the globe. The special effects business is a really good example. That work has been going to India, Thailand, China, or wherever the movie industry can find the cheapest labor. It has also required fewer people to do the same work. We are automating work faster than new jobs can be created. I am not arguing these facts to be a Luddite or pedantic. It is extremely important that we all understand this about the new new economy. We can't allow this to continue using economic principles of what work is and isn't created over 100 years ago. We are taxing the wrong things and the wrong people. If we understand at the core that people are being phased out and priced out of work, it only stands to reason that we start looking to where the productivity is happening to where taxes need to be targeted. I don't care what your position is on small government as long as we can agree that government needs to exist and has responsibilities to society like infrastructure, civic protection, law and code enforcement, etc. We can quible over the level but the money to support those tasks have to come from somewhere. We are in a system that is starving the bottom and there is gluttony at the top. As long as people believe that there are good opportunities at the bottom, people just have to look, and that there are more opportunities than are there, we have a problem. We need to offer universal and free healthcare that is NOT tied to employment as well as free training for people to change and upgrade work skills. We also need to raise the wages for people doing the jobs robots just can't do. I have never understood why a middle manager can make $100k a year and can be automated but the custodian makes $20k and his job can't.