Skip to content

Commit d63eac3

Browse files
committed
Don't crash with object-fit: non images with no intrinsic size
1 parent c790ff2 commit d63eac3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

weasyprint/layout/replaced.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ def replacedbox_layout(box):
9191
position = box.style['object_position']
9292

9393
image = box.replacement
94-
iwidth, iheight = image.get_intrinsic_size(
94+
intrinsic_width, intrinsic_height = image.get_intrinsic_size(
9595
box.style['image_resolution'], box.style['font_size'])
96+
if None in (intrinsic_width, intrinsic_height):
97+
intrinsic_width, intrinsic_height = contain_constraint_image_sizing(
98+
box.width, box.height, box.replacement.intrinsic_ratio)
9699

97100
if object_fit == 'fill':
98101
draw_width, draw_height = box.width, box.height
@@ -105,11 +108,11 @@ def replacedbox_layout(box):
105108
box.width, box.height, box.replacement.intrinsic_ratio)
106109
else:
107110
assert object_fit == 'none', object_fit
108-
draw_width, draw_height = iwidth, iheight
111+
draw_width, draw_height = intrinsic_width, intrinsic_height
109112

110113
if object_fit == 'scale-down':
111-
draw_width = min(draw_width, iwidth)
112-
draw_height = min(draw_height, iheight)
114+
draw_width = min(draw_width, intrinsic_width)
115+
draw_height = min(draw_height, intrinsic_height)
113116

114117
origin_x, position_x, origin_y, position_y = position[0]
115118
ref_x = box.width - draw_width

0 commit comments

Comments
 (0)