#๐ Font has weird gaps between some letters?
79 messages ยท Page 1 of 1 (latest)
@fringe ice
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Can you share your code? What font is it?
font_outline = ImageFont.truetype(OUTLINE_FONT_PATH, font_sizes["posttype_outline"], layout_engine=ImageFont.Layout.BASIC) draw.text(postions["posttype_outline"], match_data["posttype"], font=font_outline, fill="#7A7676", anchor="mm")
the font is Akira Expanded / Outline
It actually might just be an issue with the font...I found it online and get weird results with GAMEDAY too
Hm well in photoshop it works fine:
Try testing with some other fonts to see if they give nicer results
I'm not saying totally change fonts in the end, but it can help rule out the issue
hm nevermind it seems to be an issue with akira expanded in general. the super bold has the same issue
yeah, that's some odd kerning
can i fix this? photoshop can handle it apparently
fonts are an enigma that I haven't dove into a ton so I'm really not sure why photoshop can handle it but pillow can't
๐ฅฒ
i guess i can isolate the text in photoshop and put it on the final picture like a logo but thats akward
hm its the standard for all our social media posts so very badly i guess
so doing a bit of research, and it says some fonts have more advanced features for individual glyph kerning control and PIL's ImageFont isn't correctly making use of that
ah damn. yeah im trying to find workarounds rn with other libs etc. but didnt find something promising yet
oh that looks good. is that a lib?
It's a GUI library
you can install it with pip install pyside6
it's mostly the QtGui.QImage class you'll want to use as your canvas
ill try that
and then there's a way to convert to a PIL image again
but you'll have to do all your sizing/measurement with pyside
it worked for me with PIL out of box
from PIL import Image, ImageDraw, ImageFont
# Parameters
text = "YAYAY"
font_path = "Akira Expanded Demo.otf" # Replace with the path to your .otf font
font_size = 72
image_size = (800, 400) # Width x Height
bg_color = "white"
outline_color = "red" # Color of the outline
outline_width = 3 # Width of the outline
# Create a blank image
image = Image.new("RGB", image_size, bg_color)
# Load the font
font = ImageFont.truetype(font_path, font_size)
# Initialize ImageDraw
draw = ImageDraw.Draw(image)
# Calculate text size using textbbox
bbox = draw.textbbox((0, 0), text, font=font, stroke_width=outline_width)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]
# Center the text
position = ((image_size[0] - text_width) // 2, (image_size[1] - text_height) // 2)
# Draw the text with outline
draw.text(
position,
text,
font=font,
fill=None,
stroke_width=outline_width,
stroke_fill=outline_color
)
# Save the image
image.save("output_image.png")
print("Image saved as output_image.png")
Hey @tidal gust!
Add a py after the three backticks.
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
The font loads, but the kerning is wrong
this is using the code you pasted, but with the text they want
i got this
try it with GAMEDAY
that's weird. What PIL/python version are you using?
py 3.12
pillow==12.0.0
Akira Expanded Font | dafont.com
no im from linux but im not sure if they have different implementation for this
yeah it really shouldn't matter for this
thats basically how photoshop handles the font
sadly pillow doesnt do this for me. tried around with conda now but im more frustrated than before xD
can you share/DM your font file?
wtf. i downloaded py 3.12 real quick and
python3 -m pip install --upgrade Pillow
after. now apparently theres no module called "PIL"
on my linux machine it also have correct kerning
hm okay
what do you mean?
Pillow doesnt work for me on py 3.12.10
3.11.9 works
as soon as i swap interpreter:
Traceback (most recent call last):
File "o:\Documents\TeamBash\image_gen.py", line 1, in <module>
from PIL import Image, ImageDraw, ImageFont, features
ModuleNotFoundError: No module named 'PIL'
are you using venv?
no
i did work with linux enviorement and venv recently for other reasons. i guess ill have to try that again:( wanted to dodge that for comfort reasons
maybe the font works in the linux env then aswell
can you try
python3.12 --version
could be that python3 reference for another version
Python 3.12.10
what about python3 --version
Python 3.11.9
yeah so just call install on proper python
python3.12 -m pip install --upgrade Pillow
should help
okay atleast pillow works now on 3.12. but font still f*cked
funny enough this still shows 3.11.9
and vs code still thinks pillow is not there
because this version is still in system maybe, how this works is magic for me too. So i just always use venv/docker
fair
yeah i think as with the last project i surrender to windows... should have known better and use my linux venv form the start
Thanks for all the help tho
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.