Initial Commit
All checks were successful
Build 2 exe / Build (push) Successful in 18s

This commit is contained in:
2026-02-10 22:10:15 +01:00
commit e585d9dd4d
10 changed files with 328 additions and 0 deletions

View File

@@ -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

176
.gitignore vendored Normal file
View File

@@ -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

BIN
CONSOLA.TTF Normal file

Binary file not shown.

19
README.md Normal file
View File

@@ -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

14
build.py Normal file
View File

@@ -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"
}
)

2
input.csv Normal file
View File

@@ -0,0 +1,2 @@
User ID;Code Activation
placeholder;test
1 User ID Code Activation
2 placeholder test

BIN
marianne.TTF Normal file

Binary file not shown.

5
readme.txt Normal file
View File

@@ -0,0 +1,5 @@
Utilisation
=================
1. Remplir le fichier input.csv
2. Lancer l'application text2image.exe

19
settings.conf Normal file
View File

@@ -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"

72
text2image.py Normal file
View File

@@ -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