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

730

u/[deleted] Mar 24 '21 edited Sep 30 '26

[removed] — view removed comment

296

u/[deleted] Mar 24 '21

they don't really like automation that much - they fear it will put them out of work! But I guess they'll have embrace it for the mundane jobs like this

0

u/[deleted] Mar 24 '21

[deleted]

16

u/toyg Mar 24 '21

Well, demand for construction workers was definitely higher when they could only use shovels rather than excavators...

6

u/[deleted] Mar 24 '21

[removed] — view removed comment

12

u/[deleted] Mar 24 '21

But the total number of people employed is less, this is how efficiency happens. We are at a bad point in history where more and more tasks are being automated and fewer jobs are left for people. Add in that we look down our noses at most jobs that require people and allow those jobs to pay substandard wages. I love technology and the fact that a job like this can be automated with a few lines of code but lets look at it with eyes wide open.

8

u/[deleted] Mar 25 '21

[removed] — view removed comment

1

u/En-tro-py Mar 25 '21

It's a lack of imagination!

We're already short workers.

We can't find enough welders.

We spend the money to automate the majority of the job, now one welder can "supervise" the robots and do the actual difficult bits!

It's technically not hiring an equivalent number of welders, but also needs to be programmed, maintained, have quality control, planning, material handling from other roles...

Growth is a game of whack-a-mole.

2

u/[deleted] Mar 25 '21

This is complete bull. We are short in some areas and some welders, especially welders that are specialized in automated welding. Also 1 field being anecdotally short is not proof of what is going on in the entire system. It is absolutely true that technology is creating jobs as jobs are being eliminated. The issue is that 10 jobs are being eliminated as 2 or 3 are being created. Take the welding. Fewer old tech welders are needed because a robot can outweld 5 or 6 people. To make matters worse we don't have a way to retrain workers unless they pay for the retraining themselves in time and money. Unfortunately food, clothing, and shelter don't stop being necessities while people retrain. This makes it very difficult for people to retrain. Manufacturers in my area are crying for workers. The common refrain is "We can't find workers at any price" but the price they are offering is $12/hr - $13/hr. I ask them how someone is supposed to get from town and travel 5 -10miles to their factory? And there is no public transportation.

I was in a dark factory that makes plastic bottles you see on the shelves at wally world. The factory would have employed 100 people 20 years ago, today? 7 people. 7 people run the ENTIRE factory. Most of the place doesn't even have lights. Don't need them.

1

u/PepegaQuen Mar 26 '21

The issue is that 10 jobs are being eliminated as 2 or 3 are being created.

To do the same thing. But we're doing more things.

→ More replies (0)