feat: final details + docs
This commit is contained in:
21
image-converter/README.md
Normal file
21
image-converter/README.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Image converter
|
||||||
|
|
||||||
|
Simple tool to convert images on mass.
|
||||||
|
|
||||||
|
- Resize
|
||||||
|
- Format
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
- `-H <height>` : max height of vertical images.
|
||||||
|
- `-W <width>` : max width of horizontal images.
|
||||||
|
- `-e <extension>` : extension of the output files.
|
||||||
|
- `-d <directory>` : input directory path.
|
||||||
|
- `-f <file/s>` : file or list of files (paths) to parse.
|
||||||
|
- `-o <directory>` : output directory path.
|
||||||
|
- `-h` : print help.
|
||||||
|
|
||||||
|
### Examples of usage
|
||||||
|
|
||||||
|
- `python converter.py -d ./assets -f ./another/file.png ./yet\ one\ more/file2.CR2 -e png -W 1000` : convert every file inside assets plus both `file.png` and `file2.CR2` into `PNG` with a with of 1000.
|
||||||
@@ -1,14 +1,6 @@
|
|||||||
from modules.image_parser import (parse_image, parse_whole_directory)
|
from modules.image_parser import (parse_image, parse_whole_directory)
|
||||||
from modules.argument_parser import (generate_argument_parser)
|
from modules.argument_parser import (generate_argument_parser)
|
||||||
|
|
||||||
# NOTE: arguments
|
|
||||||
# -H <height> : max height of vertical images
|
|
||||||
# -W <width> : max width of horizontal images
|
|
||||||
# -e <extension> : extension of the output files
|
|
||||||
# -d <directory> : input directory path
|
|
||||||
# -f <file/s> : file or list of files (paths) to parse
|
|
||||||
# -o <directory> : output directory path
|
|
||||||
# -h : help
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
arg_parser = generate_argument_parser()
|
arg_parser = generate_argument_parser()
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ def generate_argument_parser():
|
|||||||
parser.add_argument("-W", "--width", type=int, help="max width for horizontal images")
|
parser.add_argument("-W", "--width", type=int, help="max width for horizontal images")
|
||||||
parser.add_argument("-e", "--extension", type=str, default="png",help="extension of the processed files")
|
parser.add_argument("-e", "--extension", type=str, default="png",help="extension of the processed files")
|
||||||
parser.add_argument("-d", "--directory", type=str, help="directory of files to process")
|
parser.add_argument("-d", "--directory", type=str, help="directory of files to process")
|
||||||
parser.add_argument("-f", "--files", nargs="+", type=list, help="list of files to process")
|
parser.add_argument("-f", "--files", nargs="+", help="list of files to process")
|
||||||
parser.add_argument("-o", "--output", type=str, default="./",help="directory for the output files")
|
parser.add_argument("-o", "--output", type=str, default="./",help="directory for the output files")
|
||||||
return parser
|
return parser
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ def parse_image(src: str, target_src: str, max_vertical_size_px: int, max_horizo
|
|||||||
max_vertical_size_px = rawImage.height
|
max_vertical_size_px = rawImage.height
|
||||||
target_height = max_vertical_size_px
|
target_height = max_vertical_size_px
|
||||||
target_width = math.ceil(rawImage.width * max_vertical_size_px / rawImage.height)
|
target_width = math.ceil(rawImage.width * max_vertical_size_px / rawImage.height)
|
||||||
else:
|
else:
|
||||||
if (max_horizontal_size_px == None or max_horizontal_size_px < 1):
|
if (max_horizontal_size_px == None or max_horizontal_size_px < 1):
|
||||||
max_horizontal_size_px = rawImage.width
|
max_horizontal_size_px = rawImage.width
|
||||||
target_width = max_horizontal_size_px
|
target_width = max_horizontal_size_px
|
||||||
@@ -31,8 +31,7 @@ def parse_image(src: str, target_src: str, max_vertical_size_px: int, max_horizo
|
|||||||
else:
|
else:
|
||||||
target_src = os.path.abspath(target_src)
|
target_src = os.path.abspath(target_src)
|
||||||
full_path = os.path.join(target_src, filename)
|
full_path = os.path.join(target_src, filename)
|
||||||
print(">> Path: ", full_path)
|
rawImage.save(full_path)
|
||||||
# rawImage.save(full_path)
|
|
||||||
|
|
||||||
def parse_whole_directory(dir_src: str, target_src: str, max_vertical_size_px: int, max_horizontal_size_px: int, target_extension: str):
|
def parse_whole_directory(dir_src: str, target_src: str, max_vertical_size_px: int, max_horizontal_size_px: int, target_extension: str):
|
||||||
for file_path in get_file_path_iter(dir_src):
|
for file_path in get_file_path_iter(dir_src):
|
||||||
|
|||||||
Reference in New Issue
Block a user