TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Automate Graphic Design using Python

Use Python Pillow to automate the creation of a hundred warehouse labels for the signage of picking locations.

Samir Saci
TDS Archive
Published in
8 min readOct 6, 2022

--

Diagram showing the automation process for creating warehouse labels using Python Pillow. It starts with an Excel file containing location and product data. A Python script reads the data to create barcodes and adds a location number and stickers. The labels include different arrows and color-coded information, designed for warehouse signage of various storage locations.
(Image by Author)

As a data scientist, have you ever wished that graphic design could be as easy as coding a script?

With Python, it can be!

You are a data scientist in the logistics department of an international fashion retailer.

Your colleagues install equipment, train the teams, and design the layouts of storage locations for each new project.

Warehouse label generated with Python Pillow with a yellow downward arrow indicating the product’s picking location, a barcode, and the SKU code 6610096077325. The label also shows icons for handling instructions: a box, a dress, and a hazardous materials symbol.
Example of Warehouse Label — (Image by Author)

Therefore, they spend a tremendous amount of time in graphic design for posters, security signage, and labels.

How can you support them with Python?

This article explores a method to automate the graphic design process using the Python library Pillow.

I. How to do graphic design with Python?
1. Scenario
You need to design several hundreds of labels for a warehouse
2. Objective and Solution
You want to automate this process using Python Pillow
II. Warehouse Label Design Workflow
1. Six key parameters
Each label is defined by components with dedicated spatial locations.
2. Information sources
An Excel file store the parameters to generate all your labels
III. Automate the label creation with Python Pillow
1. Loop Through Your Data Frame using Pandas
Extract the information of items to include with their spatial locations
2. Generate a Barcode for the SKU Code with EAN13 library
Some items need to be generated during the creation of the label.
IV. Conclusion
1. Animate Python graphs using Pillow
Another application of Pillow to bring life to your visuals

How to do graphic design with Python?

Scenario

You support the project team for the logistics department of a fashion retailer with warehouses on all continents.

This team is in charge of implementing processes and equipment for newly opened distribution centres.

Illustration of the order fulfillment process in a warehouse. Step 1: Orders are received by the admin team. Step 2: The picking team retrieves items from racks. Step 3: Items are packed into parcels for shipping.
Example of a Distribution Center — (Image by Author)

For instance, your major task is to design the layout of racks for storage locations.

You can have several hundred locations in a warehouse with pallets/shelves for storage and picking.

Front-view graphic of tall warehouse racks generated with a 3D SketchUP model, with multiple levels for storing goods. Some racks have designated picking locations on lower levels, while the upper levels are used for general storage.Examples of Racks with pallets for which we use pallets
(Ground Level: Picking Locations, Other Levels: Storage) — (Image by Author)

To help the operators find the right locations, you need to print and stick labels with key information.

Photo of a warehouse storage location showing stacked pallets on a rack. A yellow box highlights a label with a barcode attached to the front of the rack, indicating the storage location for easy identification.
Example of the label for an elevated storage location — (Image by Author)

What do we want to achieve?

Objective

You want to design customized labels that reduce errors, help operators, and respect your company's standard operating procedures.

You want to automate this process because you may have several thousand locations per warehouse.

How?

Solution

I will present a solution to automatically create these labels.

Animation with hundred Warehouse labels with a large yellow upward arrow pointing toward the storage location generated with Python Pillow. It contains a barcode, SKU code 6090761375244, and icons indicating that the stored items are boxes, pants, and should be handled with care due to liquid content.
Final Results of labels — (Image by Author)

It is a simple Python script that imports location information from an Excel file and automatically generates labels like the ones above.

Let’s have a look at it!

🏫 Discover 70+ case studies using data analytics for supply chain sustainability🌳and business optimization 🏪 in this: Cheat Sheet

Warehouse Label Design

Six key parameters

Three types of operators will read this label:

  • Reach Truck Drivers who will put pallets or boxes in these locations
  • Picking Operators that will take items from these locations
  • Inventory admins that will perform inventory counts

What do we need to include in this label?

Therefore, you must include key information related to the location and the product stored:

  • A coloured arrow to show where the product is stored (above or below)
  • A bar code with the SKU code for the operators using an RF gun
  • The picking location number with the alley, cell and level numbers
  • Three Icons that provide information related to the location and the item stored
Labeled warehouse sticker with detailed annotations showing all the components automatically added with Python Pillow. It highlights key elements such as the barcode, SKU code, color-coded arrow showing the picking location, and relevant product icons. The picking location number is displayed prominently at the bottom.
Label Information — (Image by Author)

How do we do that?

Let us split the label into single elements.

Spatial Coordinates

Considering the size of each item, you want to fix the spatial coordinate of each item.

Annotated warehouse label showing spatial coordinates for positioning icons, barcodes, and product information with Python Pillow. The label design uses a top-left corner origin system, and the arrows guide users to the correct picking location. Icons provide information on storage and handling requirements.
Key Coordinates — (Image by Author)

You have five parameters to locate the different items in this straightforward label.

We put the origin in the top-left corner because Python’s Pillow uses the same origin.

From where do we take these elements?

Import PNG icons

The storage location number and the bar code will be generated in your Python script.

Visual of a warehouse label emphasizing the color-coded arrows used for indicating storage directions. Various icons are placed on the right side to show specific product-related information such as SKU codes, packaging, and handling instructions to show the components imported automatically with Python Pillow.
Icons to add — (Image by Author)

The other items are icons that will be imported into your Pillow object using locally stored png files.

Great, now how do we know what to put in each label?

Information source

Your master data contains several thousand SKUs with information such as size, weight, price, etc.

You will allocate each of these SKUs to a picking location that will require a specific label.

For your automation tool, you can create an Excel file with a line for each SKU including.

  • SKU Code: that will be used to create the bar code
  • Geographical information: alley, zone and location number
  • Logistics handling unit: pieces if you take items piece by piece or Carton if you take the item by carton
  • Arrow type with the direction and the colour
  • Product Category (Tie, Shoes, Dress, …)
  • Picking Location Special Information: dangerous goods, sprinklers, RFID, …

Now that you have a clear idea of the workflow let us implement it in a python script.

Automate the label creation with Python Pillow

Loop Through Your Data Frame using Pandas

Your script will loop through the lines of your data frame to generate one label for each line.

For each label, you start by creating a blank canvas with a black border and specific dimensions (500, 200) in pixels.

A blank rectangular canvas with a black border is shown. The canvas dimensions are 500 pixels wide and 200 pixels tall. It is completely empty, representing the starting point before adding any graphic elements like icons or barcodes for warehouse labels.
Blank Canvas — (Image by Author)

Let’s add some illustration in this canva.

Add Icons to the Label using Python’s Pillow

For this step, you will add icons specifying

  • Coordinates (x, y)
  • Dimensions after resizing using percentage
  • Icon filename is taken from the data frame

P.S:

  • You need to convert your PNG files to keep your background transparent.
  • Icons coordinates are defined using their size on both axes
A partially completed warehouse label with icons on the right-hand side. The label features a large downward yellow arrow on the left, representing storage direction. Three black and white icons are aligned vertically: a cardboard box icon, a dress icon, and a hazard icon. These icons represent product attributes like packaging, category, and safety automatically added with python pillow.
Label with icons — (Image by Author)

This starts to look like a warehouse label.

Let us add the location information.

Generate a Barcode for the SKU Code with EAN13 library

The bar code is generated using the SKU code and the Python barcode library.

P.S:

  • create_ean will generate a PNG file stored locally and used by the script
  • The bar code has been resized to fit in the canvas
A warehouse label with a yellow downward arrow on the left and three icons (box, dress, hazard) on the right. In the center of the label is a vertically positioned barcode generated using the SKU code ‘6610096077325’. This barcode generated with Python EAN library is ready to be scanned by a handheld RF gun for logistics purposes.
Label with bar code — (Image by Author)

This bar code can be scanned by an RF gun.

However, we need to add the location names for the operators.

Add the Location Code to the Label with the Pillow

This last step will be fully performed using Python Pillow.

Warehouse label generated with Python Pillow with a yellow downward arrow indicating the product’s picking location, a barcode, and the SKU code 6610096077325. The label also shows icons for handling instructions: a box, a dress, and a hazardous materials symbol.
Final Result — (Image by Author)

Now our label is complete.

A Python script has entirely generated it.

Conclusion

Your labels are generated and ready to be printed.

Say goodbye to time-consuming graphic design tasks and hello to automation with Python Pillow.

Animation with hundred Warehouse labels with a large yellow upward arrow pointing toward the storage location generated with Python Pillow. It contains a barcode, SKU code 6090761375244, and icons indicating that the stored items are boxes, pants, and should be handled with care due to liquid content.
1000 labels generated in 30 seconds — (Image by Author)

This is not Leonardo Da Vinci's artwork, but it can be automatically generated for a thousand labels with just a click.

Do you want other applications of Python Pillow?

Generate Animated Graphs using Pillow

In another series of articles, I focus on implementing an optimization tool to reduce the walking distance of warehouse operators.

Two line plots represent the picking routes of a warehouse operator using two different algorithms. Each dot on the plot corresponds to a picking location, with dashed lines connecting the dots in the order of picking. The top plot shows Algorithm 1’s route, and the bottom plot shows Algorithm 2’s route. Each location is annotated with a number, indicating the sequence of picking locations. This visualization allows for comparing the two algorithms’ efficiency.
Two different pathfinding algorithms — (Image by Author)

The idea is to compare two pathfinding methods for a specific pick mission set.

What’s the problem?

Looking at the final results does not provide enough insights.

I used Python Pillow to generate animated plots with the two pathfinding solutions.

You can now spot when (and where) the two solutions differed.

You can find the detailed solution in this article if you want to replicate this solution.

Have you heard about Generative AI?

Boost your tool with GPT.

What if users can change the icon type or location using a prompt in plain English?

Large Language Models (LLMs) can be used to improve the user experience for reporting and advanced analytics products.

A flowchart illustrating the steps of a generative AI-powered system for answering supply chain queries. The process begins with a question mark icon representing a user query, followed by machine learning processing, SQL database querying, and additional data processing, ending with a chatbot providing answers to the user’s questions.
Supply Chain Control Tower Agent with LangChain SQL Agent [Article Link] — (Image by Author)

In a previous article, I explored the possibilities of GPT by building a smart agent connected to a TMS database.

This experiment aims to design an intelligent agent equipped with a GPT model and connected to a database.

  1. Users ask operational questions: “Where is my shipment?”
  2. The agent queries the database and extracts the results.
  3. The agent replies with a proper answer.

Can we use this agent to generated custom labels?

Yes!

After OpenAI introduced ChatGPT’s advanced features, we can deploy solutions like this label design tool in a custom GPT.

  • We can include the initial code presented here
  • The agent could change the code based on user requests

Users would upload item master data, and the agent would prepare the labels.

A diagram showing a two-step process for analyzing supply chain data using an AI agent. Step 1 is “Data Upload,” where users upload a dataset, either a CSV file or a sample file. Step 2 is “Select Variable,” where users choose between quantity and turnover for analysis. The AI agent then generates analysis with visuals, including sales distribution and demand variability charts.
“The Supply Chain Analyst” — (Image by Author)

You can get inspiration from the “Supply Chain Analyst”, a custom GPT agent I’ve designed to automate supply chain analytics tasks and interact with users using natural language.

For more details, have a look at these articles,

If you prefer watching, have a look at the YouTube tutorial

About Me

Let’s connect on Linkedin and Twitter. I am a Supply Chain Engineer who uses data analytics to improve logistics operations and reduce costs.

For consulting or advice on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting.

If you are interested in Data Analytics and Supply Chain, look at my website.

💌 New articles straight in your inbox for free: Newsletter
📘 Boost your Productivity with Data Analytics: Productivity Cheat Sheet

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Samir Saci
Samir Saci

Written by Samir Saci

Top Supply Chain Analytics Writer — Case studies using Data Science for Supply Chain Sustainability 🌳 and Productivity: https://bit.ly/supply-chain-cheat

Responses (1)