Skip to content

Create PIL_version_error.md #62

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions PIL_version_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The error occurs because the `getsize` method is no longer available in newer versions of the Pillow (PIL) library for `FreeTypeFont` objects. This method has been deprecated and removed. Specifically, the error message is:

```
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
```

This indicates that the `font.getsize()` call is not recognized as a valid method for `FreeTypeFont`.

To resolve the issue, you should replace the `getsize` method with `font.getbbox()` or `font.getmask()` in your code. The `getbbox()` method returns the bounding box (the coordinates of the character's box), which can then be used to calculate the width and height of the character. For example, replace:

```python
char_width, char_height = font.getsize("A")
```

With:

```python
bbox = font.getbbox("A")
char_width = bbox[2] - bbox[0]
char_height = bbox[3] - bbox[1]
```

This change will allow the code to run properly on newer versions of Pillow.
6 changes: 5 additions & 1 deletion img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def main(opt):
cell_height = 12
num_cols = int(width / cell_width)
num_rows = int(height / cell_height)
char_width, char_height = font.getsize(sample_character)
# char_width, char_height = font.getsize(sample_character)
bbox = font.getbbox("A")
char_width = bbox[2] - bbox[0]
char_height = bbox[3] - bbox[1]

out_width = char_width * num_cols
out_height = scale * char_height * num_rows
out_image = Image.new("L", (out_width, out_height), bg_code)
Expand Down
6 changes: 5 additions & 1 deletion img2img_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def main(opt):
cell_height = 12
num_cols = int(width / cell_width)
num_rows = int(height / cell_height)
char_width, char_height = font.getsize(sample_character)
# char_width, char_height = font.getsize(sample_character)
bbox = font.getbbox("A")
char_width = bbox[2] - bbox[0]
char_height = bbox[3] - bbox[1]

out_width = char_width * num_cols
out_height = scale * char_height * num_rows
out_image = Image.new("RGB", (out_width, out_height), bg_code)
Expand Down
9 changes: 8 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ def sort_chars(char_list, font, language):
elif language == "japanese":
char_width, char_height = font.getsize("あ")
elif language in ["english", "german", "french", "spanish", "italian", "portuguese", "polish"]:
char_width, char_height = font.getsize("A")
# char_width, char_height = font.getsize("A")
bbox = font.getbbox("A")
char_width = bbox[2] - bbox[0]
char_height = bbox[3] - bbox[1]
elif language == "russian":
char_width, char_height = font.getsize("A")
# bbox = font.getbbox("A")
# char_width = bbox[2] - bbox[0]
# char_height = bbox[3] - bbox[1]

num_chars = min(len(char_list), 100)
out_width = char_width * len(char_list)
out_height = char_height
Expand Down
6 changes: 5 additions & 1 deletion video2video.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def main(opt):
cell_height = 12
num_cols = int(width / cell_width)
num_rows = int(height / cell_height)
char_width, char_height = font.getsize("A")
# char_width, char_height = font.getsize("A")
bbox = font.getbbox("A")
char_width = bbox[2] - bbox[0]
char_height = bbox[3] - bbox[1]

out_width = char_width * num_cols
out_height = 2 * char_height * num_rows
out_image = Image.new("L", (out_width, out_height), bg_code)
Expand Down
6 changes: 5 additions & 1 deletion video2video_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def main(opt):
cell_height = 12
num_cols = int(width / cell_width)
num_rows = int(height / cell_height)
char_width, char_height = font.getsize("A")
# char_width, char_height = font.getsize("A")
bbox = font.getbbox("A")
char_width = bbox[2] - bbox[0]
char_height = bbox[3] - bbox[1]

out_width = char_width * num_cols
out_height = 2 * char_height * num_rows
out_image = Image.new("RGB", (out_width, out_height), bg_code)
Expand Down