Skip to content

Commit

Permalink
Determine mask mode in Python instead of C
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 13, 2023
1 parent 25cc5af commit f016d30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,16 @@ def getmask2(
im = None
size = None

def fill(mode, im_size):
def fill(width, height):
nonlocal im, size

size = im_size
size = (width, height)
if Image.MAX_IMAGE_PIXELS is not None:
pixels = max(1, size[0]) * max(1, size[1])
pixels = max(1, width) * max(1, height)
if pixels > 2 * Image.MAX_IMAGE_PIXELS:
return

im = Image.core.fill(mode, size)
im = Image.core.fill("RGBA" if mode == "RGBA" else "L", size)
return im

offset = self.font.render(
Expand Down
2 changes: 1 addition & 1 deletion src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ font_render(FontObject *self, PyObject *args) {

width += stroke_width * 2 + ceil(x_start);
height += stroke_width * 2 + ceil(y_start);
image = PyObject_CallFunction(fill, "s(ii)", strcmp(mode, "RGBA") == 0 ? "RGBA" : "L", width, height);
image = PyObject_CallFunction(fill, "ii", width, height);
if (image == Py_None) {
PyMem_Del(glyph_info);
return Py_BuildValue("ii", 0, 0);
Expand Down

0 comments on commit f016d30

Please sign in to comment.