A command-line application to resize all images in a directory, by getting the new size input from the user. All resized images will be saved to ./imgs/resized/
by default.
I created this as a way to study python and also because I sometimes need to bulk resize large photos taken by camera.
Any suggestions and improvements will be most welcome! 😉
It maintains the aspect ratio and orientation of the original images, but it only resizes to smaller sizes, as it's intended to reduce large photo files and also to avoid quality loss by enlarging images.
The language of all the output messages can be set using the --language
(or -l
) flag in the command line. (Default language is en_US
)
python3 resize_images.py --language pt_BR
For now, pt_BR, es_AR and en_US are already available. New languages can be added by creating a ll_LL.json
file under the ./language
directory. More information about that in the ./language/README.md
- Pillow (PIL Fork)
pip install -r requirements.txt
# or just run:
# pip install Pillow
- Copy all the image files you want to resize to
./imgs/
and runresize_images.py
:
# en_US is the default language:
python3 resize_images.py
# em português:
python3 resize_images.py -l pt_BR
# en castellano:
python3 resize_images.py -l es_AR
- To choose another image directory, use the
--images_dir
(or-d
) flag:
python3 resize_images.py --images_dir "path/to/images"
-
User will then be prompted to enter the new intended size, in pixels.
- Examples of valid input values:
> 1200px
> 1200 px
> 1200
- Examples of valid input values:
-
Or you can specify the new size for the images by using the
--size
(or-s
) flag:
python3 resize_images.py --size 600
python3 resize_images.py --size 600px
python3 resize_images.py --size "600 px"
-
Note that the user will only enter the size of the largest dimension, no matter whether it is width or height, as the aspect ratio is to be preserved.
-
All the images in the chosen directory will be resized to the same largest dimension size.
-
The resized images will be saved to
./imgs/resized
by default. To choose another destination, use the--resized_dir
(or-r
) flag:
python3 resize_images.py --resized_dir "path/to/resized"
-
The file
./log.txt
will be used (when necessary) to output extra informations, like:-
Warning whether any non image file is present in the images directory.
-
Informing that a given image file was not resized due to the new size being larger than the original image dimensions.
-
To see all the options run:
python3 resize_images.py -h
To change the default value for any of the command-line arguments, edit the config.json
file.