I'd like to control the slantiness (italic) of a text according a given degree and direction (left or right tilt) similar as presented in the image below:
I have stumble upon this great answer: How does perspective transformation work in PIL?, played with the code, and read the documentation of AFFINE but it's still isn't clear enough for me.
Can someone please explain me (mathematic and logic wise), how can I do this? Thank you.
解决方案
To generate some text we can use any method, here I am using ImageFont to get a black and white mask.
def generate_text(text):
fnt = ImageFont.truetype('arial.ttf', 72)
img = Image.new('1', fnt.getsize(text))
mask = [x for x in fnt.getmask(text, mode='1')]
img.putdata(mask)
img = img.con