#๐ Pillow related issue
106 messages ยท Page 1 of 1 (latest)
@old remnant
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.
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
!code
!paste
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.
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
i will not be clicking your link for example
I mean mystbin is a Well known site
Limitations
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
M'y bad
from typing import TYPE_CHECKING
from PIL import Image, ImageDraw, ImageFont, ImageFilter
import io
import aiohttp
import traceback
Just a normal class tho
Commands.cog class
doesn't look like you import any such modules
Its just discord.py
from discord import commands
discord bots really isn't my area, but this problem shouldn't be so much about that anyways
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?
Do u mean i set the max () on it too ?
Oh wai
except IOError:
author_font = ImageFont.load_default()```
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)
it's often somewhere on your system, i think it's a quite standard font
@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
No
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?
haha, i can see that
Too small u have to zoom it
Now its really a code issue XD
i said i can see that
what size is the image that you are overlaying the text on in this example and are you scaling the image after you have put the text on it?
The one that has interaction_or_message is the content of the middle of the pic
400x400
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
okay, just wanted to make sure it wasn't a huge image that got scaled down after the text was overlayed on the image and could cause the text to appear smaller then when it was rendered on the image
Nah
Any clue thi
Im clueless
@still pendant
However there is still small stuff
yeah, i see it, very small out on the lower right edge
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
where is this?
god the code is so long
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)
yeah, i was just a bit surprised that you didn't use
text_area_width = max(text_area_width, 350)
```there too, similar to what you do with font sizes
That's not your code
But uhh
It was just path issue when it was showing small
Texts
no, i know it's not my code
but it looks like you fixed it now ๐
Kind of
Whats the size to make them small and readable
Not so small
you probably need to try different font sizes until you are happy with the result
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)
That wasn't your Snippet*
Because it sounds rude lol
Oh
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
how do i uhhhhh deal with this
what is your expected result?
i'm guessing you don't want the text to go outside of certain bounds, right?
yes
yes
@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()```
.
Um
sorry, i had to go afk for a while, back now
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.