Skip to content

Commit fc802de

Browse files
committed
add option --fast option to pillow.py example
The fast mode calculates the modelspace extents without using matplotlib.
1 parent 810ad71 commit fc802de

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

examples/addons/drawing/pillow.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def main():
4747
default=300,
4848
help="output resolution in pixels/inch, default is 300",
4949
)
50+
parser.add_argument(
51+
"--fast",
52+
action="store_true",
53+
help="use fast bounding box calculation",
54+
)
5055

5156
args = parser.parse_args()
5257

@@ -85,13 +90,19 @@ def main():
8590
# backend would have to store all drawing commands to determine the required
8691
# image size. This could be implemented as a different pillow backend which
8792
# is optimized for speed.
88-
print("detecting model space extents ...")
93+
print(f"detecting model space extents (fast={args.fast}) ...")
8994
t0 = perf_counter()
90-
extents = bbox.extents(msp, flatten=0)
95+
flatten = 0.01
96+
use_matplotlib = ezdxf.options.use_matplotlib
97+
if args.fast:
98+
ezdxf.options.use_matplotlib = False
99+
flatten = 0
100+
extents = bbox.extents(msp, flatten=flatten)
91101
print(f"... in {perf_counter() - t0:.1f}s")
92102
print(f"EXTMIN: ({extents.extmin.x:.3f}, {extents.extmin.y:.3f})")
93103
print(f"EXTMAX: ({extents.extmax.x:.3f}, {extents.extmax.y:.3f})")
94104
print(f"SIZE: ({extents.size.x:.3f}, {extents.size.y:.3f})")
105+
ezdxf.options.use_matplotlib = use_matplotlib
95106

96107
ctx = RenderContext(doc)
97108
try:

0 commit comments

Comments
 (0)