You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it possible to generate or simulate italic text for any font other than an original italic font? #7292
What you're talking about is known as 'fake italics' - slanting text instead of using a properly designed italic font. Pillow doesn't offer that functionality, no, and I'm unable to find anything that says that FreeType supports it.
I know what italics looks like, yes. I'm saying that no, Pillow can't generate italics if the font is not italic (unless you have a variable font), and I can't find any evidence to say that FreeType (a dependency that Pillow uses to render text) does either.
Activity
radarhere commentedon Jul 19, 2023
What you're talking about is known as 'fake italics' - slanting text instead of using a properly designed italic font. Pillow doesn't offer that functionality, no, and I'm unable to find anything that says that FreeType supports it.
Unless you're talking about variation fonts, where multiple styles are contained within a single font file. That is supported by Pillow - https://pillow.readthedocs.io/en/stable/releasenotes/6.1.0.html#variation-fonts
nissansz commentedon Jul 19, 2023
Check below effect, some words slanted to right, some to left. Some normal.

radarhere commentedon Jul 19, 2023
I know what italics looks like, yes. I'm saying that no, Pillow can't generate italics if the font is not italic (unless you have a variable font), and I can't find any evidence to say that FreeType (a dependency that Pillow uses to render text) does either.
nissansz commentedon Jul 19, 2023
Any method to transform, like wavy?
nulano commentedon Jul 19, 2023
I found the following answer on StackOverflow: https://stackoverflow.com/a/51701378/1648883
The (now removed)
getsizefunction there is used incorrectly, the following is a corrected version:nissansz commentedon Jul 19, 2023
Thank you.
Which parameter to control direction and angle?
radarhere commentedon Jul 19, 2023
The
shearargument toshear().So

shear(img, 2)with FreeMono.ttf givesshear(img, 1)givesshear(img, -1)givesnissansz commentedon Jul 19, 2023
it looks good. Thank you.
nissansz commentedon Jul 19, 2023
Is it possible to use ImageFont.FreeTypeFontFamily for above function?
radarhere commentedon Jul 19, 2023
Oh, your problem is that
FreeTypeFontFamilydoesn't havegetmask.It should just be a matter of replacing
with
in your code.
But again - you use #6926 at your own risk, as it has not been finished yet.
nissansz commentedon Jul 19, 2023
I tried your code, there is below error.
nulano commentedon Jul 19, 2023
nissansz commentedon Jul 19, 2023
Ok. It works now. Thank you.
4 remaining items
nissansz commentedon Jul 20, 2023
Thank you.
nissansz commentedon Jul 20, 2023
Can bold font be realized with similar method above? Any parameters to adjust?
nissansz commentedon Jul 20, 2023
I also want to add background color for some random text, how to realize it with pillow?
radarhere commentedon Jul 20, 2023
Without a bold font or a variation font, no, Pillow can't do this, and I don't think Freetype can either.
nissansz commentedon Jul 20, 2023
Any fast method like opencv's erode, dilate to simulate bold?
nissansz commentedon Jul 20, 2023
I used pixel color replace to simulate highlight, it may be slow? Any fast method?
nissansz commentedon Jul 20, 2023
Below seems working, any improvements needed?
nulano commentedon Jul 20, 2023
Something like MaxFilter might work:
https://pillow.readthedocs.io/en/stable/reference/ImageFilter.html#PIL.ImageFilter.MaxFilter
nulano commentedon Jul 20, 2023
You can add a background by using my answer on StackOverflow: https://stackoverflow.com/a/72302587/1648883
nissansz commentedon Jul 20, 2023
thank you, will try
github-actions commentedon Jul 27, 2023
Closing this issue as no feedback has been received.