Podcast Lookup

43 - Python Image Processing with Pillow

The Python Show

  • June 6, 2024
  • 35 min
Episode page
About this episodeIn this episode, Mike has Alex Clark on the show. Alex is the leading developer of the fork of the Python Imaging Library (PIL), known as…

In this episode, Mike has Alex Clark on the show. Alex is the leading developer of the fork of the Python Imaging Library (PIL), known as Pillow.

We chatted about the following topics:

* The origins of Pillow

* Lessons learned in open source development

* Surprising use cases for Pillow

* AI and Pillow

* and much more!

Show Links

* Django - https://www.djangoproject.com/

* Wagtail - https://wagtail.org/

* Faker - https://github.com/joke2k/faker

* django-allauth - https://allauth.org/

* django-extensions - https://github.com/django-extensions/django-extensions

* django-sql-explorer - https://www.sqlexplorer.io/

* logfire - https://pydantic.dev/logfire

* Pillow demo - https://github.com/python-pillow/pillow-demo

* https://www.jeremykun.com/2012/01/01/random-psychedelic-art/

* python-pillow/Pillow#1888

* https://github.com/readme/featured/nasa-ingenuity-helicopter

* Alex’s band - https://headstraight4life.com/



Get full access to The Python Show at www.pythonshow.com/subscribe

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

43 - Python Image Processing with Pillow

00:00—
  1. Speaker 4

    Welcome to a brand new episode.

  2. Speaker 3

    Mike Driscoll, The Python Show.

  3. Speaker 4

    Hello and welcome to The Python Show. I'm your host, Mike Driscoll. And today I have my friend Alex on the show. He's the creator of Pillow, the Python imaging library. Oh. kind of the Python Imaging Library replacement since the two seven days anyway.

  4. Speaker 1

    Fork, yeah.

  5. Speaker 4

    Yeah, fork. That's a good word for it. Anyway, welcome to the show.

  6. Speaker 1

    Thank you, Mike. Great to be here.

  7. Speaker 4

    Yeah, it's great to have you. So how we usually start off my shows, I usually ask you a little bit about how you got into programming and Python specifically.

  8. Speaker 1

    Yes, I love this question, and I wrote down a little bit to answer it. In the early 80s, I programmed in BASIC on the Commodore, and I used to get the magazines and type in 10, you know, go 220 and all that.

  9. Speaker 4

    Yep.

  10. Speaker 1

    And then I didn't really think about computers. I had an Atari 2600, too, that wasn't programming, but I was that kid.

  11. Speaker 2

    Mm-hmm.

  12. Speaker 1

    And then I didn't really think about computers for about 10 years until I was at Loyola University in Maryland. And I happened to walk past the Unix lab and there was digital deck stations with like 20 inch monitors. And I saw people, you know, sitting there in the Unix lab. And I immediately switched my major to computer science from accounting to and never looked back. So back in the day in the 90s, I wrote C and went through all the CS requirement courses. And then Python happened in the early 2000s with when I was doing clone CMS development. And then I just fell in love with Python.

  13. Speaker 4

    That's cool. I haven't heard people talk about digital DEC computers in a long time.

  14. Speaker 1

    I know. It was a seductive situation for me.

  15. Speaker 4

    Yeah, those are nice. And Plotin, you don't hear about Plotin very much either anymore.

  16. Speaker 1

    No, it's still around. They're doing interesting stuff. You can now pip install it. They got to Python 3, obviously.

  17. Speaker 4

    Yeah, I think there's still a Plotin conference, if I remember correctly.

  18. Speaker 1

    Still Plone Conference every year, still an active community. I just switched my stack at some point. I didn't want to deal with the, something didn't quite, things like Django and like actually Pyramid, you know, back in the day, coming out of my Plone years, just felt like I was closer to the situation or, you know, closer to the application that I wanted to. Nothing against Plone, and I still actually fire it up from time to time. And I actually have a client right now who's moving his Oak site, so I still kind of dabble, but I feel at home in Django now after like 10 years.

  19. Speaker 4

    Yeah, I think Plone still is pretty big in government, so I don't think they're going to go away anytime soon.

  20. Speaker 1

    It's big in Europe government, I think, too.

  21. Speaker 4

    Okay.

  22. Speaker 1

    European governments. At least I've seen... examples of that.

  23. Speaker 4

    Yeah, I think their claim to fame, if I remember correctly, is that they had some of the best screen reader capabilities for a really long time.

  24. Speaker 1

    Yeah, they pioneered some CMS things and accessibility was one of them, if I recall correctly.

  25. Speaker 4

    Yeah, the accessibility, that was the word I was looking for. I don't know. I'm assuming Django does all that now too, but the time plan was like the king of accessibility in Python.

  26. Speaker 1

    It's a different world, yeah, and it's more componentized now. So you can do accessibility in general for the web, I think, and without having it being tied to your backend framework, I guess I would say.

  27. Speaker 4

    Yeah, which is nice. So do you have any favorite Python packages or modules besides Pillow?

  28. Speaker 1

    Yeah, for this one, I went through my Django favorites. Okay. So I do a lot of Django and Wagtail. Django is the framework. Wagtail is the CMS, content management system. And the first one I came across was this library faker that I absolutely love. I'm not entirely sure why, like for generating fake data. And I use it a lot when in development, when I have a form and I just want the data in it. Nothing's more annoying to me than being in development and not being able to save the form because I have to know what the input is. That drives me nuts. I love Faker. I love AllAuth, which takes care of many authentication problems out of the box as an add-on to the Django framework and Wagtail. It's blurb. They say free, secure, well-integrated, reusable authentication solution covering all functionality related to local and social user accounts. Multi-factor. So all that stuff they have code for. And let's see what else. Django Extensions has this graph model thing that I really like for showing you this enormous complex thing of all your models. And then last two I have are new products i would say people trying to market their commercialize their offering one's called django sql explorer which was really interesting in which you can install this thing in your django and then write sql queries and then save them and run them whenever you want i thought that was pretty and the nice the interface was nice and then log fire i was talking to somebody recently who said you know Pydantic. And I was like, no, I kind of know type enforcement. And then I just went down this Pydantic rabbit hole and found that the Pydantic guy started a company in which he promises to deliver, you know, the developer first experience for a, uh, century like offering called log fire. And sure enough, it's, I, you know, I, I installed it and it, I was impressed in their delivery on that promise. It's in beta, so you can go to LogFire and start using it. And there were some impressive developer-y things about it, for sure.

  29. Speaker 4

    Yeah, I think I want to say he announced that a week or two ago, like right before PyCon. It looked interesting.

  30. Speaker 1

    It's cool. It's definitely... When I saw it, I was like, yeah, like how... how is this here? And I didn't know about one of those things, but you just said it just happened.

  31. Speaker 4

    Yeah. It just happens. Yeah. I looked at it briefly, but I'm like, I think, I think the product it cooks into isn't something I have access to at the moment.

  32. Speaker 1

    I mean, it's, it's, I say century-like because you add it and then deploy it. And then it starts showing you stuff and it does it in a way that takes like five seconds or, you know, I'm oversimplifying, but they've got something right about it.

  33. Speaker 4

    Yeah, it kind of reminded me of a nicer Datadog.

  34. Speaker 1

    I remember that name, but I don't know if I ever used that product.

  35. Speaker 4

    Yeah, Datadog is basically, it consumes all of your logs and has a complicated UI system on top of it. So you send your logs up to it and you basically pay X number of, depending on the volume of logs and how many users you want to connect to it, things like that. It's not really made for Python necessarily.

  36. Speaker 1

    Yeah, I mean, that said, I'm skeptical about any service that would have me as a customer these days.

  37. Speaker 4

    Yeah. All right. Moving on, could you tell us a little bit about how the Pillow project came about?

  38. Speaker 1

    Yeah, so 2010, I was doing clone CMS development, and I was super annoyed with the deployments. The image processing library pill was deployed separately from everything else. So everything was on PyPy, except the pill library. And it was required. It was a requirement. So you couldn't run the CMS without running this thing. So, I mean, I looked at many, many deployments where... you know, the build out, which was Windows INI style configuration was like, you know, saw this stuff and then go get the image library over here. And so I think this slowly drove me insane until I, because people were repackaging it. And I referenced the people who did the actual work on the repackaging too. So one night at like three in the morning, I just took the repackaging from somewhere and, and created a GitHub for it and checked it in and did a release and called it Pillow and then published an email to the image sig, 22nd of July, saying, hey, I did this and I'm going to sleep. And there's all kinds of details that from 2010 to 2013 that are interesting. Then in 2013, Python support came along by a volunteer and we merged it. And that's what it was like for three years, it was like me and some other people whose PRs I would merge. Then when I merged the Python 3 support PR, I would say at that point, it just kind of blew up. And I think a few years later, I was like, oh, wow. Actually, I remember 2013 going somewhere and someone asking me if I was that Alex. And I'm like, yeah, okay. Fast forward again to 2018. This is how it came about. I'm kind of answering a little bit more, but the late 2018, we got funding, which was also the interesting milestone in the whole timeline, which was huge in that as a musician, it felt like getting a record deal, that sort of thing. It felt really important. So now, what, four or five years later, I think we started in 2019, It's four of us who get paid every month to keep pillowing. And we split it evenly. And it just works. So thank you, Tidelift, for that funding.

  39. Speaker 4

    Yeah, that's cool. I'm always happy to hear about OpenStars projects that get funded. And it keeps the package alive in some ways.

  40. Speaker 1

    Yeah, it's, it's, I have the since this, since that happened, I have the dream that it is a living, you know, wage amount. And I think maybe they have some people that approach that, but, you know, based on their algorithm, and, and, you know, so there's, there's someone has to market and provide value for the for the open source. And that's, yes. you know, that's what needs to happen. I don't, I'm not one of those, you know, you have to donate.

  41. Speaker 4

    Yeah. You need, uh, I think, I think Samuel call, is it Colvin, the guy who did the paid antic, you know, he seems to be successfully getting his product funded in a way.

  42. Speaker 1

    And yeah, he got VC and he has an idea, which is commendable and exciting.

  43. Speaker 4

    And you've got Astral, the people behind Ruff. Oh, yeah, yeah, yeah.

  44. Speaker 1

    I love that.

  45. Speaker 4

    I think both of those guys, they're savvy. They've got something. And I think more open source guys could probably look and even chat with those guys and just find out, how did you do this?

  46. Speaker 1

    Yeah, in fact, that's one of the things I kind of sit around thinking about. Do I have any of those ideas? The answer is usually no. And lately, I'm talking to a lot more people, which is, I think, how you get further along in whatever it is you're trying to do.

  47. Speaker 4

    Yeah, I think hanging out with people like entrepreneurs or just business people sometimes, it just gives you ideas. Just like you hang out with other senior developers and some junior developers. You'll get... ideas from both sides right help you improve so are there any lessons you've learned uh while creating pillow or maintaining it over the years yeah i think we

  48. Speaker 1

    drifted into a couple lessons there the first one that i wrote down that i thought was meaningful was that it doesn't have to be stressful so i remember in my blown cms days i was doing a lot of open source development and it was super stressful Pillow is the least stressful open source thing I've ever done. And I think that that's meaningful. And it's a good example of that it doesn't have to be stressful. And the second one I wrote down was that we just talked about, which is there needs to be marketing of these libraries for the developers so that they can earn a living wage. That lesson is very fresh for me now. And the last thing is image processing. Like I think I've dabbled in actually using the library over the years, but I did a demo where I went through the pill handbook tutorial and did all the real code for all the image processing. uh, fundamentals or, you know, introductory examples. And that was actually kind of thrilling for me.

  49. Speaker 4

    That's cool. Um, like what, what are some hard things about open source development that, you know, maybe you could just share some of those. Cause I think some people just don't understand why is it hard or why is it easier?

  50. Speaker 1

    It's frustrating to, to know what you want to do, whether it's, you know, supporting a library, working on a project, whatever it is that is, you know, there's value like Pillow. I know there's tremendous value to being delivered, a disproportionate amount of value. I mean, I talk to people all the time that tell me, you know, we're using it here, you know, big companies were using it and So that's one of the frustrating part. And the answer is marketing, but that's not easy either. So the average open source developer that wants to code and contribute needs advocates for them. And in addition to getting paid for PIL, I also advocate for lifting. the more people that are Tidelift customers, and I don't think Tidelift is unique in this. I think any company can do it, but they just happen to be doing it. And I think that we need more of those companies. So I advocate on behalf of lifters so that companies become clients and lifters can be lifted.

  51. Speaker 4

    That makes sense.

  52. Speaker 1

    It's also hard that I look around and I'm like, you know, hey, I just updated this Sphinx documentation theme. Maybe I can, you know, make a living on this. Maybe this can earn money. And Tidelift has like an API where you can go see if this, you know, whatever library you can think of can be monetized. So they've done some work to calculate whether or not they think they can get customer support to support that library. So that's hard too. things that go through my head, like, you know, Oh, well, you know, maybe if I get everyone to start using this theme on their blog or something, then I make, you know, a hundred dollars a month or something. I mean, just, yeah, there's a lot of brick walls, I would say to, to open source.

  53. Speaker 4

    Yeah, there are. Let's say I wanted to contribute to, to pillow later today. What, what's the process to contributing to pillow?

  54. Speaker 1

    It's the most meaningful process is actually to advocate on behalf of large company or on behalf of lifters and Tidelift. So you would say, for example, to your company, hey, you need to go get a Tidelift subscription because we are using this library and these guys are supporting it. that's the most meaningful way at the moment. And in fact, it gets harder after that. Like you can't just give me money or something. And if I, but if I was the pydantic guy, maybe you could give me, you know, venture capital, but I don't have that idea.

  55. Speaker 4

    Yeah. Gotcha. Are there any surprising use cases that you've seen pillow used for? Yeah.

  56. Speaker 1

    So for this one, In 2012, before Python 3 support, we had someone create random psychedelic art, which I always thought was interesting.

  57. Speaker 2

    Oh, neat.

  58. Speaker 1

    Jeremy Kuhn. You can look that up. And then recently, actually in 2016, one of our developers, Eric, created an issue about additional multi... channel image support in pillow and this is issue 1888 and this would allow more interesting use cases by both gis and vfx communities people doing you know geolocation stuff as well as visual effects for movies and tv hit a wall with with pillow where it does it goes right up to some line where it supports know some limited number of channels for some operations and if it had these additional features it could do a lot more so i'm actually thinking a lot about that in the same way that you know adding python 3 support was meaningful i'm thinking about how to help with that there's an event later this month on the 30th where we're gonna some people are gonna meet and talk about that the a meetup called moco makers And then lastly, the NASA Ingenuity helicopter badge that showed up on my profile. So apparently Pillow is on Mars. And since that happened, this was 2021 or so, you tell people, hey, it's on Mars. I actually looked for it in all their GitHub repositories. I couldn't find like nobody had it in their requirements. So we have the badge. All the developers have the badge. But I would love it if somebody out there said, oh, well, it was used... I would love more detail on that because it's a super interesting use case, but I can't find... They apparently didn't publish examples of it in use on the helicopter, which I think is not alive anymore. I don't remember. Huh.

  59. Speaker 4

    That's disappointing. I remember when that When they put that helicopter on Mars and they mentioned that Python was used, but they didn't really talk about any of the packages. You just kind of had to...

  60. Speaker 1

    If you go look, yeah, they don't talk about it in the high-level marketing stuff. But if you go look, like you say, in the repositories, you can find a lot of stuff. I just never was able to find examples from image import or from pill import image. But I'm sure it's there.

  61. Speaker 4

    Yeah, it's got to be there somewhere. I wonder if one of their own packages depends on Pillow some way.

  62. Speaker 1

    That could be too. In fact, I think I looked at that, but then I was like, all right, whatever.

  63. Speaker 4

    I know when I've looked at Pillow and it says millions of downloads a month, I'm like, who's using this? And I know a lot of it's dependencies, but...

  64. Speaker 1

    Yeah, that's a good one, too. I love to look at the stats, whether they're meaningful or meaningless is debatable. And URL Lib 3 by Seth is somewhere in the... was it 2 billion downloads per over three months or something and pillows in the 500 million. So we're, you know, like half a billion. We're like, yeah, we're getting there, but I think, yeah, I think it's, it's meaningful. ish you know i mean it you can correlate it with if you went around the world and said hey do you use you know this library and they all said no and then you could say oh well it's you know it's jenkins it's just downloading it or something yeah

  65. Speaker 4

    yeah i mean i know it's using a ton of ton of ton of packages i mean i think even pandas some of the big packages like pandas and i want to say matplotlib or what some of those i'm pretty sure you use pillow underneath

  66. Speaker 1

    Matplotlib, a lot of them may optionally work with it. We see a lot of NumPy questions on the Pillow, on GitHub issues in the Pillow repo. And there's probably a library too that is well known that relies on it, but I can't think of it offhand. And it's not such an over the top relationship that we know about it and think about it a lot.

  67. Speaker 4

    Yeah, I might be wrong about pandas. I do know that WXPython uses it because I used to be a huge in WXPython. It uses it for loading images and rendering them in the GUI.

  68. Speaker 1

    Yeah, it's interesting. I mean, and it's, it's, I'm sure it will outlive me and it's interesting to support it and You know, I'm fortunate to be around all that activity, you know, and to be involved in that.

  69. Speaker 4

    Oh, I should ask, is there like any big features that are coming up to Pillow that you can talk about?

  70. Speaker 1

    It's mostly, the project mostly runs itself. And by that, I mean, keeping up with Python, it tracks the Python code. release schedule very closely. So the most interesting thing is that it is released quarterly with bug fixes and new Python version support. The issue 1888 that I want to work on, I think, is the most interesting to me in which we possibly use an Apache thing, I can't remember the name of it, that lets us write Python that binds to C without having to write C code to add more of this multi-channel support that could come out or that could materialize in some form, maybe not a release, but this year-ish.

  71. Speaker 4

    Cool. Well, I'm excited to see what comes of that because that sounds kind of interesting, although I don't do anything in animation or anything to do with movies.

  72. Speaker 1

    I got obsessed with VFX and that community when I discovered their Linux Foundation project called Academy Software Foundation. I just started tracking all their C++ libraries, and it's an interesting community.

  73. Speaker 4

    Yeah, I used to think I'd get into visual effects, but I'm so bad at being an artist, I don't think I do very well.

  74. Speaker 1

    Yeah, I'm not a good graphic artist, but I love that complexity where they have this reference framework that they're dragging along to try to get all the studios to agree on. I love complexity like that.

  75. Speaker 4

    Yeah, I like that. I like learning about wireframe models, seeing how they made all the... The CGI.

  76. Speaker 1

    Yeah, I did download the Maya demo, and there's a guide that you move around to learn the steps of Maya, which was kind of fun.

  77. Speaker 4

    Yeah, those things are fascinating to me, but like I said, I'm not good at designing stuff like that. Anyway, so AI is big in the headlines right now. Do you think AI will have... Well, like take away from Pillow in any way or possibly even replace it at some point?

  78. Speaker 1

    Yeah, when you wrote that question or when I saw that question, I was like, no, I don't think so.

  79. Speaker 4

    I don't think so either, but I was curious.

  80. Speaker 1

    Yeah, it seems like an open-ended, you know, loaded-ish question, but obviously designed to spark the discussion. And so, no, I don't think so. But I do think that, or I know it can already write Python code, you know, for... for image processing. So that's kind of cool. I think it could also develop Pillow if it were prompted. So there's that. I think we won't use any AI generated. In fact, we had an AI submission about something that was totally wrong. Like they were like, you should just change this code. And no, I wasn't. It was wrong in an embarrassing sort of way. And then there's the AGI, which I think I'm skeptical about that it ever would exist in our lifetime. But if it did, then maybe it's writing future releases and understanding what it's doing in terms of reacting to world events. Like when XE happened, we thought about not releasing the next release until we were sure about this or that. And so that's a huge thing. So maybe AGI could do that.

  81. Speaker 4

    Yeah, I think the reason that I thought about that was that you see how that you... I mean, there's all these image generators now. You go to Bing, you go to ChatGPT or whatever, and they generate really cool images. And I'm like, you can do some of that scripting with Pillow and Python. And I'm like, well, how is that going to affect Pillow? I hope it doesn't affect it very much at all. But... I just thought I'd throw out the question since you're the pillow guy.

  82. Speaker 1

    I think that people have asked for AI-like machine learning features, and we always say that's not in this library. So I wouldn't be surprised if it's used by the AI to render. That seems like something very likely. If you said, draw me some psychedelic art and then you compared it with the 2012 psychedelic art, you know, that was done by a human. In fact, I could even, I could probably say, here's this, can you make me more of these? And it would, and how it's doing that image processing is almost, you know, who cares? It's the, it's a platform to burn, you know, an implementation detail and pillow just happens to be how you do it in, in,

  83. Speaker 4

    Yeah.

  84. Speaker 1

    Python are one of the ways, one of the most popular ways for really basic image processing.

  85. Speaker 4

    Yeah. Huh. Well, cool. I'm glad you were willing to discuss it, at least.

  86. Speaker 1

    Yeah, I love it. I mean, I'm in ChatGBT 4.0. I noticed I can ask it now about stuff. It searches the web now. I mean, I'm riding the ChatGBT wave, at least, or have been. Not so much modeling. People try to get me into training my models and stuff. Not so much interested in that.

  87. Speaker 4

    Yeah, I haven't tried that at all. I'm interested in machine learning, but they talk about rig and LLM and training this, that, and the other thing. The terminology just goes over my head right now.

  88. Speaker 1

    It's actually quite frightening in terms of the neural networks. First of all, I'll say about it, like every time machine learning versus deep learning comes, I have to look it up and remember, you know, cause I can never just remember which one's which. And the neural network that, you know, neural networks being part of that technical stack is terrifying in that, you know, so much is happening there that, that the, creators of the neural network don't know you know what the what the outcome will

  89. Speaker 4

    be so yeah that's a little bit scary yeah yeah that's something i'm trying to keep my eye on it because i know i'll probably need to know some of that stuff someday

  90. Speaker 1

    but there's a site hugging face that everyone tells me about that's like yes i'm sure you've heard of it you can you know get a head start on on Yeah, I guess it gives you other people's models that are shared socially or something like that.

  91. Speaker 4

    I think it does. Yeah, I know. I know several people who post about it fairly regularly. And I probably should go to that website. There's a bunch of free material on Amazon and Microsoft's website. But I don't know. I just don't have time. I think so. Yeah. All right. So let's, uh, move on to the next question. Uh, are there any non-technical hobbies that you enjoy? Yeah.

  92. Speaker 1

    So I'm a musician, uh, head straight band.com is, is where you can find out about my alternative rock. And I'm on Spotify with, with zero month monthly subscribers. So you can check that out. And iTunes, um, He it's been hard to, I like multi instrumentation. Like I like to play the, you know, the drums and the guitar and do vocals and stuff. And it's been hard lately with the state of the world. And, you know, I'm actually looking for Python, Django, Wagtail, React, AWS, you know, projects to work on. Um, I recently left NIH after like 10 years. So. It's hard to find time for those things, but as soon as I read that, I knew what my non-technical hobby answer was going to be. I still feel really strongly about it. I still pick up the guitar. It's kind of like Python programming, just that visceral feeling of playing the instrument.

  93. Speaker 4

    That's cool. I love listening to music, so I'll definitely check it out.

  94. Speaker 1

    There's some good, there's a EP three song and there's an album and the EP is my favorite. The album I think was, has some decent material on it, but had a lot of on almost like open source drama, you know, it looks like I had a lot of, didn't go that, you know, exactly the way I wanted it to. So there's always that.

  95. Speaker 4

    Yeah. I'll get the, I'll get the links from you after the, after we get done with the show so I can show them in the show notes. So everyone else can check it out. All right. Well, I think that wraps up everything I was going to ask you today. So thank you so much for being on the show today, Alex.

  96. Speaker 1

    Thank you. Yeah, that was great. I really enjoyed talking to you.

  97. Speaker 4

    Yeah, thank you. And I'll also include links to Pillow and some of the other packages we talked about so everyone else can check it out as well.

  98. Speaker 3

    Enjoying this episode? Leave a review now. Mike Driscoll, The Python Show.