Hello, guys, welcome back to take dose. And in this video, we shall see five different types of resizing an image. Okay, so we will see resizing an image down scale up scale preserving aspect ratio, resizing, only height or only width and resizing only height or only width to a specific size and resizing by using a fixed width. Comma height dimension. Okay, so these five types you will see if you have not yet subscribed to our channel. Then please do so in order to watch more on programming videos. So let us get started. Let us first write the code for resizing an image down scale preserving aspect ratio. Okay, we will do our operations in this folder. Okay, intake those desktop, then take tours. Okay, and this is our code resize dot P Y which we will write, and this is our image which will be resizing, so let us look at the original image. This is the original size of the image. Okay, as you can see it so that when we resize it, you will be able to understand now. Let us write the code First. What we will do is we will have to read the image. See v2 Dot. I am read and the name of the picture. Reynaldo, dot jpg. Okay, second thing which you will need to fix Is we will need a scale percent. Okay, so I will write the variable name a scale percent and I will use 0.5 0 Suppose we want to scale it down by half, Okay, The width by half and the height, also by half that means 50% the size of the original image then. I will give 0.5 That means 50 by 100 Okay, now we will have to define our width and height that means the new width and the new height that will be equal to integer of image dot shape at 1 that means the first parameter the parameter at the second bar because the parameter written as height by width and then multiply it with the scale percent. So what this will do is that this will take the original width and we’ll multiply it with the scale percent, so if the original width is 100 then it will be multiplied with 0.5 and it will become 50 okay, and this would return us a floating type constant, which needs to be converted to integer. Okay, so we have, type-cast added, so it will be stored in our width, and then the next thing we need is our height. We will do the same operation image dot shape at zero and we will multiply it with the scale percent because we wanted both of them to scale down, okay, preserving the aspect ratio. Now we will have to define our dimension. So what will be our dimension? It will be the calculated width comma, the calculated height. Okay, so since we have all dimension now, we can resize our image, so we will have to write resize equal to see v2 dot resize and it will take the following parameters. It will take the image matrix which we had read. It will take the new dimension. Okay, so we will write just dimension and the interpolation technique to be used. We will use inter area okay now. The resized image matrix has been stored in this resize variable. Okay, now the next thing, which we will do is let us print the shape in order to see what is the new dimension. Okay, So I will just print the research dot shape in order to see the new dimension. Then let us see the image which we have resized by using CB2 dot. I am sure not sure I am sure. And then the output window name, I will just give it as output and the matrix resized. Now we can also write it, right it to our hard-disk. If you want to save our image, so let us write it as well resized. Rinaldo dot jpg. That means the filename, which we want to resize and the matrix, the image matrix. The next thing which we will do is we will just include a weight key so that the output freezes we will be able to see it, and then, as usual, we will include destroy all windows, So what this thing is doing is it is reading the image defining a scale percent by what percent we want to decrease or increase the image size. Then we are decreasing or increasing that means scaling both the width and height, so that aspect ratio is also maintained. And then we are defining the new dimension and using that dimension, we are resizing our original image, and after that we are printing it in order to see what are the new dimensions, and we are also seeing it on our windows that means as an output and also writing it to our folder. OK, and after that when we click anything, it will quit so in our folder, you can see that there is no image named as researched. Reynaldo, dot jpg. OK, so let us run the code. The name of this is resized or P white And I will just copy it and run it. Oops, some error is coming. I think it is in line Number 3 ok? See, v2 Dot. I am read, not just read. I am read. OK, let us now run it OK again. An error is coming in Line 10 The Interpolation will be see v2 Dot in Terraria and not just in Terraria. So these are the typos. I keep making another one is coming named. Dimension is not different in line 10 okay here. The variable name should have included an N. This is also a typo. Let us now again, run it and you can see that. Our image has been aft as you can see it. If we open the original image and here you can see that resized. Rinaldo Jpg has been written. So let me open the original image. You can see that this is of half size. Okay, you can see that the width is also half and height is also half. If I just press Q, it will quit and let us close it. This is how we can resize an image, downscale, preserving aspect ratio. Okay, for upscaling. We just need to put a value of more than one here and it will just upscale, so let me put it here 3.5 and if I run it, it will just greatly increase the size, but the resolution was very less so it has been increased 3.5 times and so it is looking like a blurred image. Okay, so this is how you can upscale preserving aspect ratio, the third thing, which we will see is resizing only the height or only the width. Okay, let us just resize only the height, so the width part will only include the original width, so it will be image dot shape, so this will store the original width and height will be scaled to 3.5 times. Okay, so if I again run the code, then you can see that the height is 3.5 times of the original image. Well, the width remains the same. Okay, so this is the way to resize only height or width. Okay, if you want to do it for any specific height or a specific width, We will have to just comment it or don’t. Include the scaling percentage as you want to increase it to a given size and let us say we want to increase the height to say 800 Okay, so just save it and around the code and this height is 800 okay, irrespective of what the original height was, it will be converted to 800 to a given specific height. We can do it for them specifically. Well, okay, so the next thing, which you will see is how to do it for a fixed width or height. So this is very simple as well as you can guess it suppose. We want to make it for 704 so that I so the new dimension would become 700 comma 800 okay, and this will also scale it. Okay, let me quit it. Let me again! Run the code and see how it is doing so you can see that the width has also increased. It is 700 and the height is 800 It is more than the width. So these are the five ways of resizing anyways. I hope this video was helpful to you. If you have any type of problem, then please comment below and also comment the videos which you want to see me applaud next. And if you want to see more on programming videos, then please subscribe to our Channel. See you in our next video, thank you.