Python 3 Pillow Script to Download Image From URL & Save it to Local Machine as PNG or JPG Image
388 views
Jun 3, 2025
Buy the full source code of application here:
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I'll show you a Python
0:04
script by which you can
0:06
download an image file from a URL and
0:11
save it inside your local machine as a
0:14
JPG or PNG image so this is my Python
0:16
script we are specified this image right
0:19
here which is located at this address
0:22
it's a PNG image and for this purpose we
0:25
are using the pillow library and this
0:27
specific package which is URL2 image
0:30
which is a free Python module which
0:32
allows you to download images from URL
0:35
so if I just run this Python script so
0:37
now what happens it goes to that URL
0:40
downloads the image and save this image
0:42
inside your
0:44
uh current working directory so just see
0:48
the image has been successfully
0:50
downloaded and saved so this is we
0:54
provided this image which is located at
0:56
this address right here if you
0:58
see so you don't need to manually right
1:02
click and save this image we can use
1:04
this Python script so now let me show
1:06
you which modules you will need for this
1:09
so this one you just need to install it
1:12
url2
1:14
image so yeah so this will is just
1:17
simply install
1:18
this this package i've already in
1:22
installed it and after that we also need
1:25
the pillow library as well so this is a
1:27
image processing library for saving the
1:30
image
1:31
file we need these two packages so after
1:34
that now we just need to create a simple
1:38
script i will show you step by step how
1:41
to do this so just create a simple app
1:44
py file and uh now we just need to
1:48
import the modules from pillow we need
1:50
to import the image module and then we
1:53
need to import this URL to image module
1:56
and then the operating system
1:59
module and then here we need to specify
2:01
a URL so now let's suppose I take a
2:04
different image i go to my website which
2:07
is
2:07
procodestore.com and here I copy the
2:12
URL so this can be any image which is
2:15
located inside the internet so just copy
2:17
the image address and simply paste
2:21
it so after
2:24
this we just need to convert this URL to
2:28
an actual image for this we use this
2:31
module URL to image and it contains this
2:34
convert method and here we take the URL
2:37
and then convert this into a image
2:40
object so after do doing this we now
2:43
need to get the current working
2:45
directory for this we use the operating
2:48
system
2:49
module dot directory name OS.path we
2:53
need to get the absolute
2:55
path and
2:57
uh in this way we will get the current
2:59
working directory after that we simply
3:03
save the file operating system path dot
3:08
join we take the script directory and
3:11
then we provide a name to the file so
3:14
let me call this as result
3:16
dot
3:18
jpg so then we simply save the file by
3:22
using the pillow library it contains the
3:24
save function and we save that at this
3:27
location and then we simply print out a
3:30
simple line to the user that image
3:33
downloaded and saved that's all that is
3:37
needed inside the script guys uh so let
3:40
me just delete this image and again run
3:43
the
3:44
script so it will take some time and
3:47
then it will download this image and
3:49
save it so this is your actual image
3:51
guys which is successfully downloaded
3:53
from that URL so this is your Python
3:56
script so thank you very much for
3:58
watching this video please hit that like
4:00
button subscribe the channel and also
4:03
check out my website freemediattools.com
4:06
uh which contains thousands of tools
#Photo & Image Sharing
#Photo & Video Sharing
#Software