Image Download Tool With Python

Image Download Tool In Python
Image Download Tool In Python

Are you new to Python? Are you looking for some free cool Python tool?

If yes, then you are on the right page 👍

In this article series, I am going to discuss exactly, what you are looking for.

Python is one of the most popular programming languages in the world. Every day, more and more people are using Python for solving simple real-life problems.

Look at Python’s popularity at the moment. The PYPL site has ranked Python as the number one place in terms of popularity.

source: PYPL

There are several other online resources, where you can get theoretical knowledge about Python. In fact, there are official websites for Python and also a vibrant community.

However, there are not many resources where you get a ready-made Python tool that exactly solves your problem domain. I have been using Python for the last 8+ years and have developed various tools to solve real-life problems. So, I am going to share those Python tools with you and also explain to you how these tools work.

Problem Domain

There is a lot of time when I wanted to download a bunch of photos one by one. I had 100 different image URLs and I had to download them one by one.

Imagine copying 100 URLs one by one and then pasting them in the browser and then downloading them and naming them sequentially. Definitely, it’s a time-consuming task.

Can you automate it using Python? Absolutely, YES! 💪👍

I just wrote a couple of lines of code that probably saved 15-20 minutes of my life! Of course, writing the tools will take time, but, hey, that’s only for the first time. From the second time onwards, you are just gonna run the tool and save your time.

Since I have already built the tool, and I am gonna share it with you, you don’t have the spend time to creating the tool.

If you got the same problem, you are just gonna download the file and execute it!

List of the Image URLs, I wanted to Download

I am not going to share the whole list of 100 URLs that I wanted to download. Rather, I am just sharing the three sample image URLs that I am considering to demonstrate this tool.

  1. https://bit.ly/2SLa41A
  2. https://bit.ly/3iHH3ys
  3. https://bit.ly/3dkrWd9

Of course, I have shorten these links for easy usage.

What I want to Automate

I want to download these links automatically through a Python script. So, I will run a Python tool that will download all these three files for me. I don’t have to open these URLs manually and download them.

Python Tool

Here is the Python that I used to automate this task:

# Importing all the required modules
import urllib.request

# Image URL List
filename = ''
Image_URL_List = [ "https://bit.ly/2SLa41A",
                   "https://bit.ly/3iHH3ys",
                   "https://bit.ly/3dkrWd9"]

counter = 1
for each_url in Image_URL_List:
    filename = str(counter) + '.jpg'
    print(filename)

    # Download each image url
    urllib.request.urlretrieve(each_url, filename)

    counter = counter + 1
                   

As you can see, by using these 9 lines of Python code, you can automatically download as many images as you want automatically.

So, in your case, if you want to download 50 images, you need to collect the URLs and update the “Image_URL_List” variable in the above program at Line Number 6. Then you can execute the program and all your 50 images will be downloaded and saved in your current directory from where you are executing the Python program.

Python Tool Output

Here is the output of the Python tool:

Python Tool Output
Tool Output

Here, you can see that I got the three images downloaded and they are named as “1.jpg”, “2.jpg”, “3.jpg”. You get the file saved in the same order as you mention the URLs in the “Image_URL_List” variable.

How the Tool is working

The working principle of the tool is very simple. It imports the urllib package which helps us with the downloading part.

It then loops through each image URL at a time and downloads them by using the urlretrieve() function in urllib package.

By the way, I am planning to improve the tool by adding a file read function that allows us to just put all the URL links in a text file and then run the tool. This would be much easier to use for sure.

Can I download the image in PNG instead of JPG format?

Definitely. You just need to change the extension at Line number 12.

Download The Tool

You can download the Python tool by Clicking Here.

Summary

Python is a well-known and very popular programming language at the moment all over the world.

Today, in this article – Python Tools Series – 1, I have explained step-by-step, how to create a Python script/tool to download 100/1000 images in one go. If you have 10,000 images to download, you can just run the tool and go for a coffee break 😉

If you have any questions, please feel free to comment in the comment box below 👇👇👇

In the next series, I will share some other tools that might be useful for solving your real-life problems.

Stay Tuned!

Create Image Download Tool With Python
Scroll to top
error: Content is protected !!