initial commit
This commit is contained in:
commit
01d800230c
2 changed files with 91 additions and 0 deletions
33
README.md
Normal file
33
README.md
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# datedStampGenertaor
|
||||||
|
A python tool using PIL to generate PNGs of scanned stamps, for multiple dates.
|
||||||
|
# Purpose
|
||||||
|
This tool's objective is to solve a problem by automating a manual task.
|
||||||
|
|
||||||
|
In the context of signing digital documents, a stamp must be applied. This can be done digitally from an image from software such as ABBYY finereader.
|
||||||
|
To make this image (PNG with transparency) this is the workflow :
|
||||||
|
- Apply the stamp to a piece of paper
|
||||||
|
- Scan the paper in high resolution
|
||||||
|
- Open the resulting image in Photoshop
|
||||||
|
- Mask the background to make it transparent
|
||||||
|
- Crop the image to only have the stamp
|
||||||
|
- Save as PNG
|
||||||
|
|
||||||
|
When then is a dated stamp, whith a changeable date within the stamp impression, it means every date must be converted to a digital PNG individually. This is time consuming.
|
||||||
|
|
||||||
|
# What this tool does
|
||||||
|
Using PIL, this tool picks from a previously scanned collection of images to combine them into a realistic looking stamp.
|
||||||
|
The stamp is separated in parts:
|
||||||
|
|
||||||
|
- Outside ring
|
||||||
|
- Day
|
||||||
|
- Month
|
||||||
|
- Year
|
||||||
|
|
||||||
|
The tool iterates through every date and generates, then saves the corresponding stamp.
|
||||||
|
It picks from different variations of every eement to make a unique stamp each time.
|
||||||
|
|
||||||
|
# Weaknesses
|
||||||
|
|
||||||
|
This tool generates impossible dates (such as 31 february)
|
||||||
|
This tool needs to be supplied with a lot of input data (approx 2h work in photoshop)
|
||||||
|
This tool does not use OOP
|
58
main.py
Normal file
58
main.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
from PIL import Image as img
|
||||||
|
import random
|
||||||
|
import os
|
||||||
|
import errno
|
||||||
|
############################
|
||||||
|
#Start date
|
||||||
|
|
||||||
|
for y in range(2020,2026):
|
||||||
|
for m in range(1,13):
|
||||||
|
for d in range(1,32):
|
||||||
|
|
||||||
|
|
||||||
|
############################ 123445
|
||||||
|
#generate random numbers
|
||||||
|
variations = [14,2,2,2]
|
||||||
|
|
||||||
|
randomVariations = [0,0,0,0]
|
||||||
|
#for the circle
|
||||||
|
randomVariations[0] = random.randint(1,variations[0])
|
||||||
|
print(randomVariations[0])
|
||||||
|
|
||||||
|
#for the day
|
||||||
|
randomVariations[1] = random.randint(1,variations[1])
|
||||||
|
print(randomVariations[1])
|
||||||
|
|
||||||
|
#for the month
|
||||||
|
randomVariations[2] = random.randint(1,variations[2])
|
||||||
|
print(randomVariations[2])
|
||||||
|
|
||||||
|
#for the year
|
||||||
|
randomVariations[3] = random.randint(1,variations[3])
|
||||||
|
print(randomVariations[3])
|
||||||
|
|
||||||
|
|
||||||
|
#import elements
|
||||||
|
|
||||||
|
circle = img.open(os.path.join("data/circles/" + str(randomVariations[0]) + ".png"), "r")
|
||||||
|
day = img.open(os.path.join("data/days/" + str(d) + "/" + str(randomVariations[1]) + ".png"), "r")
|
||||||
|
month = img.open(os.path.join("data/months/" + str(m) + "/" + str(randomVariations[2]) + ".png"), "r")
|
||||||
|
year = img.open(os.path.join("data/years/" + str(y) + "/" + str(randomVariations[3]) + ".png"), "r")
|
||||||
|
|
||||||
|
tampon = img.composite( circle, day, circle)
|
||||||
|
tampon = img.composite( tampon, month, tampon)
|
||||||
|
tampon = img.composite( tampon, year, tampon)
|
||||||
|
|
||||||
|
# Rotate the stamp slightly
|
||||||
|
tampon = tampon.rotate(random.randint(-10,10), img.BILINEAR)
|
||||||
|
|
||||||
|
filename = "generated/" + str(y) + "/" + str(m) + "/" + str(y) + "-" + str(m) + "-" + str(d) + ".png"
|
||||||
|
if not os.path.exists(os.path.dirname(filename)):
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(filename))
|
||||||
|
except OSError as exc: # Guard against race condition
|
||||||
|
if exc.errno != errno.EEXIST:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
tampon.save(filename)
|
Loading…
Add table
Add a link
Reference in a new issue