#๐Ÿ”’ Pillow related issue

106 messages ยท Page 1 of 1 (latest)

old remnant
#

.g

crimson pythonBOT
#

@old remnant

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.

old remnant
#

Uh sorry
I am actually struggling with pillow issue where my texts literally are small

#

I will share my code

#

Pillow related issue

#

Its shows it like this

#

Very small

still pendant
#

!code

crimson pythonBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

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

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

still pendant
#

!paste

crimson pythonBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

still pendant
#

use one of the above options instead for sharing code, that or a github/gitlab link (or some other major platform), it's the only way we know the links are safe

still pendant
old remnant
old remnant
still pendant
# old remnant Happy now XD

yes, but i think it's not all of your code, for example the class definition is missing and any imports would also be helpful

old remnant
old remnant
#

Commands.cog class

still pendant
old remnant
#

from discord import commands

still pendant
#

discord bots really isn't my area, but this problem shouldn't be so much about that anyways

old remnant
still pendant
# old remnant Yeah its just in my pillow code

you are doing the font size calculations with max() to set a lower bound ๐Ÿ‘
but you aren't using it if you end up in the IOError exception code, in that case you use the default, could that be the problem here and why you have too small font sizes?

old remnant
#

Oh wai

old remnant
#

you mean this part?

#

@still pendant actually i don't have arial

#

in my folder

#

si yeah it uses default

#

which means the default shows it small

#

@still pendant Use load_default() only when you can't find a TTF font, but accept that the font will be small and non-scalable.

#

that's on their docs

#

it means that i need a font and their default can't be adjuted

#

xhere can i find arial.ttf font ?

#

(i don't haveit on my side)

still pendant
#

@old remnant anyways, i think we have found the source of the problem, maybe you don't want to fall back to using the default but instead bailout and produce an error message instead if this happens as well as log an error in your logs that will make finding what went wrong easier

#

this was the only code path in your code that i could find that would produce the text with the small font

#

@old remnant you might want to import logging and use it to produce an error log file which you can track down problems like this by using a logger to write warnings and errors in the log when you go down one of these code paths that you preferably should never hit

old remnant
#

My system uses one default

still pendant
# old remnant My system uses one default

i understand, but it is typically still somewhere on your storage medium that holds your OS so that the OS can use it for other programs as it's a very common font
which OS are you using?

still pendant
#

haha, i can see that

old remnant
#

Now its really a code issue XD

still pendant
still pendant
old remnant
old remnant
#

overlay canvas width is calculated to be approximately 1.65 times the profile picture width (minimum 350 px)

#

@still pendant my code doesnt scale the image after overlaying the text; the text is drawn directly onto the canvas

still pendant
still pendant
#

yeah, i see it, very small out on the lower right edge

old remnant
still pendant
# old remnant Yeah idk why

i'm surprised you didn't employ the same kind of logic here with max() to set the minimum limit as you did with for example the font size

if text_area_width < 350: text_area_width = 350
old remnant
#

god the code is so long

old remnant
still pendant
still pendant
#

but it looks like you fixed it now ๐Ÿ‘

old remnant
#

Kind of

old remnant
#

Not so small

still pendant
#

this looks like you are overwriting the same variable quite a few times and could probably be substantially simplified

            text_area_width = int(original_pfp_w * 1.65)
            if text_area_width < 350: text_area_width = 350
            if original_pfp_w > 400 and text_area_width < original_pfp_w * 0.85:
                text_area_width = int(original_pfp_w * 0.85)
old remnant
#

Because it sounds rude lol

still pendant
# old remnant That wasn't your Snippet*

no, i understand that it wasn't my little snippet of code that solved it
it wasn't to fix the font size that i commended on that code
it was just an unrelated comment just like the one above

still pendant
old remnant
#

yes

old remnant
#

@still pendant help

#

it still doesn't work even with this

#
def get_fitting_font(self, text, max_width, max_height, font_path="database/arial.ttf", max_font_size=40, min_font_size=8):
        font_size = max_font_size
        while font_size >= min_font_size:
            try:
                font = ImageFont.truetype(font_path, font_size)
            except IOError:
                font = ImageFont.load_default()
                break
            text_bbox = font.getbbox(text)
            text_width = text_bbox[2] - text_bbox[0]
            text_height = text_bbox[3] - text_bbox[1]
            if text_width <= max_width and text_height <= max_height:
                return font
            font_size -= 1
        try:
            return ImageFont.truetype(font_path, min_font_size)
        except IOError:
            return ImageFont.load_default()```
old remnant
#

.

old remnant
#

Um

still pendant
#

sorry, i had to go afk for a while, back now

crimson pythonBOT
#
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.