commit e585d9dd4d1619389f5f90de3bc2afcadcb01ba8 Author: Jason Secula Date: Tue Feb 10 22:10:15 2026 +0100 Initial Commit diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..eaf7511 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,21 @@ +name: Build 2 exe +run-name: building text2image +on: [push] + +jobs: + Build: + runs-on: windows + steps: + - name: Check out repository code + uses: actions/checkout@main + - name: Building exe file + run: | + python ${{ gitea.workspace }}\build.py + mkdir ${{ gitea.workspace }}\dist\images + 7z -tzip a text2image ${{ gitea.workspace }}\dist\* + ls ${{ gitea.workspace }} + - name: Release + uses: softprops/action-gh-release@v2 + with: + files: | + ${{ gitea.workspace }}\text2image.zip \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36b13f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,176 @@ +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + diff --git a/CONSOLA.TTF b/CONSOLA.TTF new file mode 100644 index 0000000..e881ca4 Binary files /dev/null and b/CONSOLA.TTF differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c9fadc --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# text2image + +Python script to generate images from text using a csv file. + +Configuration & tweaking +================= +Edit settings.conf to tweak and configure the tool. + + +Usage +================= + +1. Insert data into input.csv, 1st column is filename, 2nd column is text : +|filename|text | +|--------|-----| +|image001|test | +|image002|test2| + +2. Launch text2image.exe to generate images diff --git a/build.py b/build.py new file mode 100644 index 0000000..296c29f --- /dev/null +++ b/build.py @@ -0,0 +1,14 @@ +import py2exe + +py2exe.freeze( + console=['text2image.py'], + data_files=[ + ('',['CONSOLA.TTF',"marianne.TTF",'input.csv', 'settings.conf']) + ], + options={"bundle_files": 1}, + version_info={ + "version": "1.0", + "description": "Outil pour générer des images à partir des infos d'un fichier CSV", + "company_name": "DRU Nancy-Metz" + } +) \ No newline at end of file diff --git a/input.csv b/input.csv new file mode 100644 index 0000000..9360d9c --- /dev/null +++ b/input.csv @@ -0,0 +1,2 @@ +User ID;Code Activation +placeholder;test \ No newline at end of file diff --git a/marianne.TTF b/marianne.TTF new file mode 100644 index 0000000..5676823 Binary files /dev/null and b/marianne.TTF differ diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..90e8a68 --- /dev/null +++ b/readme.txt @@ -0,0 +1,5 @@ +Utilisation +================= + +1. Remplir le fichier input.csv +2. Lancer l'application text2image.exe diff --git a/settings.conf b/settings.conf new file mode 100644 index 0000000..eb17f50 --- /dev/null +++ b/settings.conf @@ -0,0 +1,19 @@ +[csv] +inputFile = "input.csv" +separator = ";" +skipFirstLine = true + +[image] +width = 180 +height = 40 +# RGB value encased in [] or colorName or int value +bgColor = [255,0,0] +font = "CONSOLA.TTF" +# RGB value +fontcolor = [0,0,0] +fontsize = 22 +# left, right, center or int value +alignment = "center" +# center, top, bottom or int value +verticalAlign = "center" +outputPath = "./images" \ No newline at end of file diff --git a/text2image.py b/text2image.py new file mode 100644 index 0000000..4a60aae --- /dev/null +++ b/text2image.py @@ -0,0 +1,72 @@ +from PIL import Image, ImageDraw, ImageFont +import csv +import toml + +conf = None + +with open('.\settings.conf', mode='r') as c: + conf = toml.load(c) + +inputFile = conf["csv"]["inputFile"] +separator = conf["csv"]["separator"] +skipFirstLine = conf["csv"]["skipFirstLine"] + +imgWidth = conf["image"]["width"] +imgHeight = conf["image"]["height"] +textFont = conf["image"]["font"] +bgColor = conf["image"]["bgColor"] +fontColor = conf["image"]["fontcolor"] + +if(type(fontColor) == type([])): + fontColor = (fontColor[0],fontColor[1],fontColor[2]) + +if(type(bgColor) == type([])): + bgColor = (bgColor[0],bgColor[1],bgColor[2]) + +fontSize = conf["image"]["fontsize"] +alignment = conf["image"]["alignment"] +verticalAlign = conf["image"]["verticalAlign"] +outputPath = conf["image"]["outputPath"] + +with open(inputFile, mode='r') as file: + csvFile = csv.reader(file, delimiter=separator) + i = 0 + + for lines in csvFile: + if(i == 0 and skipFirstLine): + i += 1 + continue + + text = lines[1] + outputFileName = lines[0] + + image = Image.new("RGB", (imgWidth, imgHeight), bgColor) + draw = ImageDraw.Draw(image) + # select font + font = ImageFont.truetype(textFont, size=fontSize) + textlength = draw.textlength(text, font=font) + + # Horizontal alignment of text + if(alignment == "center"): + xtext = (imgWidth - textlength) // 2 + elif(alignment == "left"): + xtext = 5 + elif(alignment == "right"): + xtext = (imgWidth - textlength-3) + else: + xtext = int(alignment) + + # Vertical alignment of text + if(verticalAlign == "center"): + htext = (imgHeight+3 - fontSize) // 2 + elif(verticalAlign == "top"): + htext = 2 + elif(verticalAlign == "bottom"): + htext = (imgHeight - fontSize) + else: + htext = int(verticalAlign) + + # draw image + draw.text((xtext, htext), text, font=font, fill=fontColor) + image.save(f"{outputPath}/{outputFileName}.png") + i += 1