installation guide and script
This commit is contained in:
parent
891e323094
commit
002395f5e8
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
54
app/cli.py
Normal file
54
app/cli.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import argparse
|
||||||
|
import os.path
|
||||||
|
import pathlib
|
||||||
|
from app.watermark import watermark_text_bottom_right
|
||||||
|
|
||||||
|
_FONTS_DIR = pathlib.Path(__file__).parent / "fonts"
|
||||||
|
_DEFAULT_FONT = str(_FONTS_DIR / "Roboto-Regular.ttf")
|
||||||
|
|
||||||
|
|
||||||
|
def _find_all_files(folder: str, mask: str) -> list:
|
||||||
|
root = pathlib.Path(folder)
|
||||||
|
return [f"{os.path.join(file.parent, file.name)}" for file in root.rglob(mask, case_sensitive=False) if '_wm' != os.path.splitext(file.name)[0][-3:]]
|
||||||
|
|
||||||
|
|
||||||
|
def _build_output_filename(filename: str) -> str:
|
||||||
|
file = pathlib.Path(filename)
|
||||||
|
basename, extension = os.path.splitext(file.name)
|
||||||
|
newfilename = f"{basename}_wm{extension}"
|
||||||
|
print(f"file={file}, basename={basename}, extension={extension}, newname={newfilename}")
|
||||||
|
return f"{os.path.join(file.parent, newfilename)}"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser("watermark")
|
||||||
|
parser.add_argument("-f", "--font", required=False, default=_DEFAULT_FONT, help='TTF Font file (default: bundled Roboto-Regular)')
|
||||||
|
parser.add_argument("-t", "--text", required=True, help='Text watermark')
|
||||||
|
parser.add_argument("-i", "--input_filename", required=False, help='Input filename')
|
||||||
|
parser.add_argument("-if", "--input_folder", required=False, default=".", help='Input folder (default: current directory)')
|
||||||
|
parser.add_argument("-m", "--file_mask", required=False, default="*.jpg", help='File mask (default: *.jpg)')
|
||||||
|
parser.add_argument("-o", "--output_filename", required=False, help='Output filename')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.input_filename is not None:
|
||||||
|
watermark_text_bottom_right(
|
||||||
|
input_image_path=args.input_filename,
|
||||||
|
output_image_path=args.output_filename,
|
||||||
|
text=args.text,
|
||||||
|
font_path=args.font,
|
||||||
|
pos=(1000, 200),
|
||||||
|
size=60)
|
||||||
|
else:
|
||||||
|
files = _find_all_files(args.input_folder, args.file_mask)
|
||||||
|
print(f"files={files}")
|
||||||
|
for file in files:
|
||||||
|
newfilename = _build_output_filename(file)
|
||||||
|
if os.path.isfile(newfilename):
|
||||||
|
continue
|
||||||
|
watermark_text_bottom_right(
|
||||||
|
input_image_path=file,
|
||||||
|
output_image_path=newfilename,
|
||||||
|
text=args.text,
|
||||||
|
font_path=args.font,
|
||||||
|
pos=(1000, 200),
|
||||||
|
size=60)
|
||||||
BIN
app/fonts/Roboto-Regular.ttf
Normal file
BIN
app/fonts/Roboto-Regular.ttf
Normal file
Binary file not shown.
0
app/fonts/__init__.py
Normal file
0
app/fonts/__init__.py
Normal file
BIN
dist/py_watermark-0.1.0-py3-none-any.whl
vendored
Normal file
BIN
dist/py_watermark-0.1.0-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/py_watermark-0.1.0.tar.gz
vendored
Normal file
BIN
dist/py_watermark-0.1.0.tar.gz
vendored
Normal file
Binary file not shown.
26
install.sh
Executable file
26
install.sh
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Установка watermark как глобальной команды
|
||||||
|
#
|
||||||
|
# После установки запуск из любой директории:
|
||||||
|
# watermark -t 'текст' -m '*.JPG'
|
||||||
|
#
|
||||||
|
# Параметры:
|
||||||
|
# -t текст водяного знака (обязательный)
|
||||||
|
# -if папка с фото (по умолчанию: текущая директория)
|
||||||
|
# -m маска файлов (по умолчанию: *.jpg, регистр не важен)
|
||||||
|
# -f путь к TTF-шрифту (по умолчанию: bundled Roboto-Regular)
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
|
echo "Сборка пакета..."
|
||||||
|
poetry build
|
||||||
|
|
||||||
|
echo "Установка..."
|
||||||
|
python3 -m pip install --force-reinstall dist/py_watermark-*.whl
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Готово. Проверка:"
|
||||||
|
watermark --help
|
||||||
@ -12,6 +12,13 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
watermark = "app.cli:main"
|
||||||
|
|
||||||
|
[tool.poetry]
|
||||||
|
packages = [{include = "app"}]
|
||||||
|
include = ["app/fonts/Roboto-Regular.ttf"]
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|||||||
5
run-1.sh
Executable file
5
run-1.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
poetry run python main.py -t 'Кострома
|
||||||
|
фото: Вячеслав Бойко, bvn13.me' -i samples/input.jpg -o samples/output.jpg -f fonts/Roboto-Regular.ttf
|
||||||
|
|
||||||
3
run.sh
3
run.sh
@ -1,5 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
poetry run python main.py -t 'Кострома
|
poetry run python main.py -t 'фото: Вячеслав Бойко, bvn13.me' -if './' -m *.jpg -f /home/bvn13/develop/py-watermark/fonts/Roboto-Regular.ttf
|
||||||
фото: Вячеслав Бойко, bvn13.me' -i samples/input.jpg -o samples/output.jpg -f fonts/Roboto-Regular.ttf
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user