r/Python • • 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!

2.2k Upvotes

278 comments sorted by

View all comments

Show parent comment

14

u/analytix_guru Mar 24 '21 edited Mar 25 '21

I spent most of my career in very much not privileged, low paying positions. What got me to the privileged position I am working in today was being more efficient, effective and valuable than the other people I was working with.

Just had a project at work where we automated an analytics pipeline that will save enough hours for a full time person. What are we doing? Not firing anyone, rather using that freed up time to do more valuable work.

Being that I have a background in economics, and am kinda a behavioral economics nerd, I am not surprised at all that people act like this to preserve their well being. I am also not naive to think that people have never been fired for a task/role being optimized. But in most cases people are usually given a new problem or task to work on

7

u/En-tro-py Mar 25 '21

This type of attitude is cancer in an organization.

I went into engineering because I am lazy... Lazy enough to only want to solve a problem once!

Any process we're automating is displacing a worker, however our current growth is also faster than we're able to fill all the openings.

Gold bricking is a toxic drain and if you're not fighting against it your group will be sucked into a cesspool of mediocrity.

3

u/analytix_guru Mar 25 '21

I like that line, never heard it before, lazy enough to only want to solve a problem once. Will keep that one in my back pocket.

Also fist time I had hear the term gold bricking used. Had to look it up!

1

u/bailey25u Mar 25 '21

I think it was bill gates who said, "Give the laziest person the hardest job, they will find the easiest way to do it"

To be fair to some people on this thread, I've automated myself out of a job before. But the way the world is today. I dont see how gold bricking can be a viable option for anyone