#๐Ÿ”’ Font has weird gaps between some letters?

79 messages ยท Page 1 of 1 (latest)

fringe ice
#

Hi,

im currently creating a script that includes placing an outline font on a picture. sadly i get these weird gaps. Im using pillow and tried setting the layout_engine parameter to basic/raqm but nothing happened. im on windows 11.

Thanks in advance for any help:)

junior jettyBOT
#

@fringe ice

Python help channel opened

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.

oblique lance
fringe ice
#

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

oblique lance
#

It actually might just be an issue with the font...I found it online and get weird results with GAMEDAY too

fringe ice
#

Hm well in photoshop it works fine:

oblique lance
#

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

fringe ice
#

hm nevermind it seems to be an issue with akira expanded in general. the super bold has the same issue

oblique lance
#

yeah, that's some odd kerning

fringe ice
#

can i fix this? photoshop can handle it apparently

oblique lance
#

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

fringe ice
#

๐Ÿฅฒ

#

i guess i can isolate the text in photoshop and put it on the final picture like a logo but thats akward

oblique lance
#

yeah that's not ideal

#

how badly do you need to use that font?

fringe ice
#

hm its the standard for all our social media posts so very badly i guess

oblique lance
#

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

fringe ice
#

ah damn. yeah im trying to find workarounds rn with other libs etc. but didnt find something promising yet

oblique lance
#

me too

#

ok it looks like Qt (PySide) is a lot smarter about fonts

fringe ice
#

oh that looks good. is that a lib?

oblique lance
#

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

fringe ice
#

ill try that

oblique lance
#

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

fringe ice
#

okay thx

#

ill keep that in mind

tidal gust
#

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")
junior jettyBOT
#

Hey @tidal gust!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
oblique lance
#

this is using the code you pasted, but with the text they want

tidal gust
#

i got this

oblique lance
#

try it with GAMEDAY

tidal gust
oblique lance
#

that's weird. What PIL/python version are you using?

tidal gust
#

py 3.12
pillow==12.0.0

oblique lance
#

same pillow version here

#

where did you download the font?

tidal gust
oblique lance
#

yeah same

#

very weird

#

are you on windows?

tidal gust
#

no im from linux but im not sure if they have different implementation for this

oblique lance
#

yeah it really shouldn't matter for this

fringe ice
#

sadly pillow doesnt do this for me. tried around with conda now but im more frustrated than before xD

tidal gust
fringe ice
#

wtf. i downloaded py 3.12 real quick and

python3 -m pip install --upgrade Pillow

after. now apparently theres no module called "PIL"

tidal gust
#

on my linux machine it also have correct kerning

fringe ice
#

hm okay

fringe ice
#

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'
tidal gust
#

are you using venv?

fringe ice
#

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

tidal gust
#

can you try
python3.12 --version
could be that python3 reference for another version

fringe ice
#

Python 3.12.10

tidal gust
#

what about python3 --version

fringe ice
#

Python 3.11.9

tidal gust
#

yeah so just call install on proper python

python3.12 -m pip install --upgrade Pillow

should help

fringe ice
#

okay atleast pillow works now on 3.12. but font still f*cked

fringe ice
#

and vs code still thinks pillow is not there

tidal gust
#

because this version is still in system maybe, how this works is magic for me too. So i just always use venv/docker

fringe ice
#

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

junior jettyBOT
#
Python help channel closed for inactivity

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.