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

334

u/cbunn81 Mar 24 '21 edited Mar 24 '21

Better they do the automation themselves rather than wait around for clients to leave for another company that uses automation.

44

u/[deleted] Mar 24 '21

Code for designers!

14

u/sewerinspector Mar 24 '21

Fantastic username, el guapo

→ More replies (3)

9

u/XecutionerNJ Mar 25 '21

Yeah, Apple made the iPhone because the nokia and sony Ericsson phones were getting to be really good ipods and would destroy apples product line.

When others are innovating you out of work, you have to get on the innovation side and kick yourself out of work. Either that or wait for obsolescence.

11

u/cbunn81 Mar 25 '21

Steve Jobs himself said that if you don't cannibalize your own business, someone else will. I remember reading about that when the iPad came out, because apparently done within Apple were worried that it would cannibalize their laptop sales. Well, sure, but you also broaden your consumer base, so it's a net positive. And it would only be a matter of time before another company made a popular tablet, anyway. Then you'd have to play catch up.

→ More replies (1)
→ More replies (1)
→ More replies (2)

0

u/[deleted] Mar 24 '21

[deleted]

56

u/bailey25u Mar 24 '21

My supervisor is at that point right now all the time. I automated most of our job while he was out for 3 weeks. When he got back and saw me doing a lot of extra tasks for other teams, he freaked out. When I showed him how much of our job is now automated, he tried to undo everything I did. Fortunately, I showed our manager who said we had to keep those processes in place

→ More replies (9)

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.

0

u/[deleted] Mar 24 '21

[deleted]

→ More replies (4)

8

u/[deleted] Mar 25 '21

[removed] — view removed comment

6

u/toyg Mar 25 '21

Employment numbers have become a political football in most countries, so they are often debatable in terms of reliability. The growth of the working poor is undoubtedly real though, with more and more people working even multiple jobs (and hence often double-counted in stats) but low-paid and unstable; that’s because they are employed at the margins of automated processes, doing things that are too difficult for robots but not difficult enough for a human to command a high wage. At the other end, we have the booming technocratic class (to which I myself belong), constantly reinventing the wheel in order to justify their jobs, but very likely to eventually be squeezed in numbers like specialized factory workers were squeezed once the wave of innovation slowed down in their sector.

Automation, in our current system, doesn’t serve people - it serves capital efficiency and profit. It’s undoubtedly an unstoppable force in the long run, but maybe we should think harder about how to get it to serve people instead.

→ More replies (5)
→ More replies (3)

9

u/Gorstag Mar 24 '21

About a year ago I got laid off work due to myself and my colleague making our department significantly more efficient (Over many years). Around the same total revenue but about half the incoming workload. So they basically cut our staff in half at all levels and I got the axe. The departments that were an absolute clusterfuck due to mismanagement and other reasons... no cuts at all.

So I do get the sentiment also, because ultimately being too efficient can end up working you out of a job.

→ More replies (1)
→ More replies (5)

40

u/beisenhauer Mar 24 '21

Automate the boring stuff, amiright?

→ More replies (1)

42

u/d64 Mar 24 '21

You know how consulting companies that have done some kind of a job many times before will bill a customer say 40 hours for doing it, even though it might take them only 6 hours to do, because of their expertise?

Employees can and should do the same. Say this job was said to take days. Tell you will do it, then write the script or use Photoshop batches or whatever, be done in 45 minutes. Then spend the rest of the day on your own projects, then report triumphantly that you managed to pull it off in just one day. You are seen as efficient, but you are not shooting yourself in the foot by revealing the job can actually be done in no time at all.

22

u/[deleted] Mar 24 '21

It's not my main job - I'm a job coordinator so I handle the requests for work. I just program on the side for fun and wanted to help out. I guess I need to be careful it doesn't open a door for them to request more of this and I land myself in a hole!

7

u/sodjanathan Mar 24 '21

The kind of hole that brought me so many sql reports requests at work with no extra pay

→ More replies (4)
→ More replies (6)

57

u/killersquirel11 Mar 24 '21

It'd also be approachable with imagemagick and some bash fu

16

u/riffito Mar 24 '21

With IrfanView on Windows (or Wine) you could do it from a GUI.

IrfanView... the only software that I never changed for anything else since 1997.

→ More replies (3)

13

u/lolinux Mar 24 '21

This was exactly my thought! However, since OP is attracted to Python, I can only cheer! You usually use the tools you know and trust best for the task you have at hand!

8

u/killersquirel11 Mar 24 '21

Yep. Definitely not knocking OP at all - whatever code solves the problem is the right code in a situation like this.

It's neat to see the ways that different people will go about solving a problem.

→ More replies (3)

6

u/SecretAtLarge Mar 24 '21

Whatever they are, we all have learned they cant google if their life (or career) depended on it.

→ More replies (9)