Save Coworkers From Dying With Python Watermarks | by Martin Andersson Aaberge | Oct, 2023
[ad_1]
It was late spring, and we were wrapping up all projects before summer. When summer is around the corner, you know what to do — throw a summer party.
I was in charge of the table logistics. The party planner had this creative idea where the seating cards were pictures of the guests. I was also told to create separate signs for food intolerance.
Some people were lactose intolerant, some had gluten allergies, and some would die if they ate shrimp.
Being the Python nerd I am, I wanted to know if we could combine the two. What if we made seating cards where the allergies were already burned in?
So, I did just that.
Thankfully, I had the best starting point one could hope for. The person who collected all the data and photos made a fantastic spreadsheet.
It had three columns — name, filename of the photo, and allergies. This story’s examples are anonymous, and the photos are replaced with AI-generated photos.
I started by sketching how the results would look and writing the pseudo-code. The actual code can change quite a lot when we start programming, but treating it as a sketch is nice.
'''
fetch the spreadsheet entries:- filenames
- allergies
We don't really care about the names because the photo is their way of seeing
where they are seated.
define a folder with the icons for the allergies.
calculate the size of the images. We want to make sure the watermark
ratio is the same so we get some consistency no matter the image size.
use pillow to overlay the images.
save new image with the filename plus a suffix
If no allergies,copy over the photos.
'''
Since the icons should be consistent across all seating cards, we need to calculate the percentage the icons should cover. We want to add it to the bottom right of the photo. (If you are up for the challenge…
[ad_2]
Source link