Python 3 Pillow Script to Resize & Crop Image Using resizeimage Library
39 views
Jun 3, 2025
Get 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 will show you how to
0:04
resize and crop your image inside Python
0:07
using a package which is resize image
0:10
library so let me show you first of all
0:13
the third party library that we are
0:15
using for this application so just go to
0:17
this website just search for this
0:20
library which is resize image so this is
0:23
a third party package which is
0:28
there so yeah so this is actually the
0:30
library python resize image simply
0:34
install this the command is very simple
0:37
pip install python resize image after
0:40
that we simply
0:43
uh import this package so let me just
0:47
show
0:48
you the
0:50
script so just create a simple app py
0:53
file so we have a quite a number of
0:55
images there inside we have process here
0:58
so let's suppose I want to resize this
1:00
image i simply create a Python script
1:04
and for this we also need the pillow
1:08
library which is again a image
1:10
processing library so also install this
1:13
as well so just search for pillow and uh
1:16
this is actually a image library simply
1:18
install this library as well so after
1:21
that we import this pillow library and
1:24
then we import the resize image library
1:26
as well
1:28
after that we open this image input
1:31
image 1 jpg so we are opening this input
1:36
image
1:38
in read
1:40
plus binary mode
1:51
and just need to close this
1:56
so after that we will simply call this
1:58
function which
2:03
is f and as
2:09
image and then we simply call this
2:12
resize image module so we are simply
2:15
calling this resize image module and
2:18
here it contains this function resize
2:21
and cover function and here we specify
2:25
the coordinates so if you want to resize
2:27
to 200 by 200 the width and the height
2:30
and then we can simply save this image
2:33
which will be
2:35
resized dot
2:37
jpg and image dot
2:40
format so this completes your
2:42
application we actually took the
2:45
original image we open this image resize
2:47
it to 200 by 200 so if I go to the
2:50
terminal and just execute this command
2:53
here python app py you will see function
2:56
app object has no attribute
3:01
cover so
3:04
resize so I call this incorrect method
3:08
which is
3:09
resize cover yeah so this is actually
3:11
the method resize cover so just again
3:16
execute this you will see a new file
3:19
will be created which is resized jpg and
3:22
your image has been successfully cropped
3:25
and resized to 200 by 200 this was the
3:28
original
3:29
image sorry this was the original image
3:33
bigger and this is actually a resized
3:35
image if I say 100 by
3:39
100 you will now see once again it will
3:42
resize it to 100 by 100 you can see that
3:46
so very simple
3:47
script and we can take any other image
3:51
let's suppose
3:56
2.jpg so you can see that your image has
3:59
been successfully cropped and
4:02
resized so it's a very good library you
4:05
can definitely use it resize image which
4:08
actually crops and resize your your
4:14
image you can here provide any
4:16
coordinate here this is your width this
4:18
is your height simply change this
4:26
accordingly so in this way you can crop
4:28
any section inside the image and resize
4:32
it so this was the script guys this was
4:35
the modules that we used thank you very
4:37
much for watching this video and also
4:38
check out my website
4:41
freemediattools.com which contains
4:43
thousands of tools
#Programming
#Software