top of page
  • scotteells

ChatGPT and Python: Automating Mundane Tasks in Content Production - A Beginner's Guide

Updated: Jul 31


Ever get bogged down in bulk photo-editing tasks, bulk file-renaming, or bulk image-resizing in your content production or digital asset management role? I'm going to show you how easy it is using Python, a high-level programming language, and ChatGPT, an AI model from OpenAI. No worries, I'm keeping it Mac-friendly and beginner-proof.

Why Automate?

Automation is the secret weapon of efficient digital asset managers and content producers (photographers, illustrators, art directors etc.) - or anyone else working with tons of files that need tidying up. Let's see why:

  1. Image Resizing: Need your images in multiple sizes for different platforms? Instead of doing this manually, let's get Python and tools like Pillow or ImageMagick to do it.

  2. File Renaming: Got a bunch of files named in alien lingo? Use Python to rename them all at once, based on your rules.

  3. Metadata Handling: Handle metadata like a pro with Python libraries like ExifRead and ExifTool. Extract, modify, or embed metadata with just a few lines of code.

And this is just the tip of the automation iceberg...

Chatting with ChatGPT

ChatGPT is a language model that can generate Python code for you - you don't need to know how to write a single line of code. Just ask a basic question like, "Hey ChatGPT, how do I resize 5,000 images?" and it will provide the answer along the Python code you need to do it.

And then it will tell you how to run that code - just ask.

At the time of this writing, ChatGPT 4 is worth the upgrade over the free model, it just provides better code and better troubleshooting than the free version using ChatGPT 3.

Better than asking a basic question is learning how to craft your prompts to get exactly what you want, this is known as "prompt engineering." It's important to remember that ChatGPT is not great at guessing what what you mean - you should tell it exactly, especially if it starts getting complicated. Here's an example of what a prompt might look like to help you accomplish a task:

  • I have a folder of document files, the directory path is: /Users/MyName/Desktop/folderOfHotShots Inside that folder are ten folders.

  • In each of those ten folders, there are a number of subfolders, each containing a number of image files. I need a python3 script to extract all the files in all directories under: /Users/MyName/Desktop/folderOfHotShots

  • But add the text “HotShots” and “_” to the beginning of their file name. So the format to rename files is: [HotShots]_[Original Filename].[extension]

  • Let’s start by giving an example: There is a file in those folders named “12_13_2017_Shanghai.jpg” I need this file to be renamed: “HotShots_12_13_2017_Shanghai.jpg”

  • Then, I need this file, and all files after being renamed, to be resized to 1,000 pixels wide, saved and copied to this directory: /Users/MyName/Desktop/AllFinalFilesReadyToGo

  • If a file is not an image file then it can be skipped, but should be logged in the terminal window so I know it was skipped.

Do you understand or need any more information?

ChatGpt Proving Python Code
Here's what the output for that prompt looks like

In my experience, taking the time to carefully think though what you want it to do and including it in a well thought out prompt save a lot of time in the long run.

Saving and Running Python Code

  1. Write or copy the code (you'll notice ChatGpt provides a one-click button to copy all the code) into a text editor. Atom is a free and beginner-friendly option.

  2. Save the file with a .py extension, like "".

  3. To run your Python script, open Terminal (under applications > utilities on your Mac. It's not a pretty environment, but you'll feel like a hacker using it), and type "python3" and then drag your .py file from the finder window and drop it into the terminal, hit "enter"and voila! Your script is running.

Installing Python Libraries

Python libraries extend the capabilities of Python. To install a library, use the following command in Terminal: pip3 install library_name. ChatGPT can also suggest and give you the full command to easily install these.

For your work, consider these libraries:

  1. Pillow: For image processing tasks.

  2. ExifRead, pyexiv2, ExifTool: For reading and writing image metadata.

  3. Shutil, os: For file operations like renaming and moving files.

Troubleshooting with ChatGPT

When something goes awry, you can ask ChatGPT about the error message you're encountering. Just copy the error, paste it into a conversation with ChatGPT, it will understand the error and tell you how to respond.

A Couple Caveats

Remember, your code is powerful - it can rename thousands of files in an instant... including in ways you didn't intend. Always back up your files before running any scripts on them. Second, a lot of the apps you have may already have the functionality you're looking for - file renaming for example, is a breeze in apps like Photo Mechanic, or Bridge, though Python can handle more complicated renaming tasks.

Finally, don't upload any proprietary information to any of these platforms. All the LLM's ( large language models) are already in trouble for training their models by scraping the open internet. Make sure you aren't uploading any private/company information that could land you in trouble.

Keep Learning

Python and ChatGPT are just the beginning. Check out resources like Automate the Boring Stuff with Python for more ways to use Python in your workflow. There are a TON of good videos on YouTube for the visual learners. New AI apps, like AutoGPT, God Mode, AgentGPT promise to take even more of the work out of these processes for you - AutoGPT can access the open internet to search on the best way to accomplish tasks (ChatGPT's training data comes from 2021, so does not know about any new tool developments) and can run locally so you don't have to do anything but approve it's game plan. We're still in the early stages, so running something like AutoGPT is way more complicated than typing requests into ChatGPT, but it's just a matter of time.

So that's it. You're ready to let Python and ChatGPT take over your repetitive tasks so you can focus on the creative and strategic aspects of your work. Just remember, with great power comes great responsibility - or at least the need for good backups. Happy coding...

bottom of page