Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no attribute "textsize" on imagedraw #2

Open
xLz06 opened this issue Nov 3, 2023 · 1 comment
Open

no attribute "textsize" on imagedraw #2

xLz06 opened this issue Nov 3, 2023 · 1 comment

Comments

@xLz06
Copy link

xLz06 commented Nov 3, 2023

hi, im succesfully run the code. but when im trying to export, there's error on line 106.
this the error message;

line 106, in on_export_image
char_width = temp_draw.textsize(char, font=font)[0]
^^^^^^^^^^^^^^^^^^
AttributeError: 'ImageDraw' object has no attribute 'textsize'.

and this is the code ;

 def on_export_image(self, event):
        lines = self.richTextCtrl.GetValue().split('\n')
        selected_font = self.font_choice.GetStringSelection()
        max_line_width = 0
        temp_image = Image.new("RGBA", (1, 1))
        temp_draw = ImageDraw.Draw(temp_image)

        for line_no, line in enumerate(lines):
            line_width = 0
            for char in line:
                font = ImageFont.truetype(f"./fonts/{selected_font}", self.font_size)
106--->   char_width = temp_draw.textsize(char, font=font)[0]
                line_width += char_width

i've already rewrite and trying fix the problem by changing the code, but the error still the same. maybe anyone or the developer it self can help. because this is for my class project. thanksss

@luxuriant777
Copy link
Owner

luxuriant777 commented Nov 4, 2023

Hello, this could be due to using an incorrect version of the Pillow library where the attribute might be different or deprecated.

Did you install this lib with the command?

pip install Pillow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants