I would like to resize the images in the folder at once in Python.
When I google, the resize of the specified size will appear, but
If it is within the scope of the IF, it will not be resized.
if outside the scope of the regulations (less than or equal to)
Resize vertically, horizontally, or vertically according to regulations.
I would like to make a decision that
I'm an idiot, so I'm getting confused with IF, so I'd appreciate it if you could let me know.
The regulations are
I want both sides to fit between 3000px and 4000px.
(maintaining aspect ratio)
If it doesn't fit, I'd like to adjust the larger one to the upper limit.
Thank you for your cooperation.
python3 image
Perhaps it gets complicated and confusing because you try to put them together in one if
statement as much as possible.
Originally, it cannot be a simple condition, so you just have to divide it into several steps.
Here's an example of how to think, since it's a bit cheap to present the source code as it is.
By the way, suppose that you have already searched and can process files one by one, or that you can obtain vertical and horizontal sizes from image files or change vertical and horizontal sizes.
You can break down the vertical and horizontal sizes of the images and separate them into the following groups.
And if you add up the vertical as the number of 10 and the horizontal as the number of 1, you'll see the following groupings:
0010203
10 11 12 13
20 21 22 23
30 31 32 33
Among the above, those belonging to 11, 12, 21, and 22 groups are between the upper and lower limits, so they do not change the size.
Also, since the aspect ratio must be maintained and the larger one must be the upper limit, groups of 02,20 whose vertical and horizontal values are exactly the upper limit must not be resized.
The rest of the group is divided into vertical or horizontal values.
Use each of the following actions to derive new values for resizing:
You can resize them to the vertical and horizontal values shown in those calculations.
If you program the above as a resize process for each file, you should be able to do what you want.
© 2024 OneMinuteCode. All rights reserved.