Compare commits
1 Commits
main
...
feat/api-f
| Author | SHA1 | Date | |
|---|---|---|---|
| d37bf6e980 |
@@ -3,4 +3,10 @@
|
||||
My personal set of tools to ease and speed up my development experience.
|
||||
|
||||
1. `colorizer`: color model converter.
|
||||
2. `image-converter`: simple image formate and size converter.
|
||||
|
||||
## Compiling
|
||||
|
||||
To compile the program on your local environment simply run:
|
||||
|
||||
- `$ cargo build --release`
|
||||
|
||||
|
||||
1
api-faker/.gitignore
vendored
Normal file
1
api-faker/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
7
api-faker/Cargo.lock
generated
Normal file
7
api-faker/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "api-faker"
|
||||
version = "0.1.0"
|
||||
6
api-faker/Cargo.toml
Normal file
6
api-faker/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "api-faker"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
0
api-faker/src/assets/names.csv
Normal file
0
api-faker/src/assets/names.csv
Normal file
|
|
3
api-faker/src/main.rs
Normal file
3
api-faker/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{md,py}]
|
||||
charset = utf-8
|
||||
|
||||
[*.py]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
6
image-converter/.gitignore
vendored
6
image-converter/.gitignore
vendored
@@ -1,6 +0,0 @@
|
||||
/venv
|
||||
/venv/*
|
||||
__pycache__/
|
||||
/build
|
||||
/dist
|
||||
*.spec
|
||||
@@ -1,16 +0,0 @@
|
||||
install:
|
||||
echo ">>> Installing dependencies"
|
||||
pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
|
||||
build:
|
||||
pyinstaller src/main.py --onefile
|
||||
|
||||
save:
|
||||
pip freeze > requirements.txt
|
||||
|
||||
run:
|
||||
python src/main.py
|
||||
|
||||
setenv:
|
||||
python -m venv venv
|
||||
@@ -1,21 +0,0 @@
|
||||
# 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,6 +0,0 @@
|
||||
iniconfig==2.3.0
|
||||
packaging==25.0
|
||||
pillow==12.1.0
|
||||
pluggy==1.6.0
|
||||
Pygments==2.19.2
|
||||
pytest==9.0.2
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 248 KiB |
Binary file not shown.
@@ -1,18 +0,0 @@
|
||||
from modules.image_parser import (parse_image, parse_whole_directory)
|
||||
from modules.argument_parser import (generate_argument_parser)
|
||||
|
||||
if __name__ == "__main__":
|
||||
arg_parser = generate_argument_parser()
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
print(args, args.extension)
|
||||
|
||||
# Parse directory
|
||||
if (args.directory != None):
|
||||
parse_whole_directory(args.directory, args.output, args.height, args.width, args.extension)
|
||||
|
||||
# Parse individual files
|
||||
if (args.files != None):
|
||||
for file in args.files:
|
||||
parse_image(file, args.output, args.height, args.width, args.extension)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import argparse
|
||||
|
||||
def generate_argument_parser():
|
||||
parser = argparse.ArgumentParser(prog="Image Processor", description="A simple image format convert and resize tool.", epilog="Use any combination of arguments.")
|
||||
parser.add_argument("-H", "--height", type=int, help="max height for vertical 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("-d", "--directory", type=str, help="directory 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")
|
||||
return parser
|
||||
@@ -1,43 +0,0 @@
|
||||
from PIL import Image
|
||||
|
||||
import os
|
||||
import math
|
||||
|
||||
def parse_image(src: str, target_src: str, max_vertical_size_px: int, max_horizontal_size_px: int, target_extension: str):
|
||||
if (src == None):
|
||||
return
|
||||
if (target_extension == None):
|
||||
target_extension = "png"
|
||||
rawImage = Image.open(src)
|
||||
|
||||
if (rawImage.height > rawImage.width):
|
||||
if (max_vertical_size_px == None or max_vertical_size_px < 1):
|
||||
max_vertical_size_px = rawImage.height
|
||||
target_height = max_vertical_size_px
|
||||
target_width = math.ceil(rawImage.width * max_vertical_size_px / rawImage.height)
|
||||
else:
|
||||
if (max_horizontal_size_px == None or max_horizontal_size_px < 1):
|
||||
max_horizontal_size_px = rawImage.width
|
||||
target_width = max_horizontal_size_px
|
||||
target_height = math.ceil(rawImage.height * max_horizontal_size_px / rawImage.width)
|
||||
|
||||
rawImage = rawImage.resize((target_width, target_height))
|
||||
|
||||
filename = os.path.basename(src)
|
||||
last_dot = filename.rfind(".")
|
||||
filename = filename[:last_dot] + "." + target_extension
|
||||
if (target_src == None):
|
||||
target_src = os.path.abspath(os.path.dirname(src))
|
||||
else:
|
||||
target_src = os.path.abspath(target_src)
|
||||
full_path = os.path.join(target_src, filename)
|
||||
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):
|
||||
for file_path in get_file_path_iter(dir_src):
|
||||
parse_image(file_path,target_src, max_vertical_size_px, max_horizontal_size_px, target_extension)
|
||||
|
||||
def get_file_path_iter(directory):
|
||||
for dirpath,_,filenames in os.walk(directory):
|
||||
for f in filenames:
|
||||
yield os.path.abspath(os.path.join(dirpath, f))
|
||||
Reference in New Issue
Block a user