Skip to content

Commit 7211dae

Browse files
JorjMcKiejamie-lemon
authored andcommitted
Demo some matrix effects
In response of a documentation feedback, we are adding a short demo.
1 parent 37775de commit 7211dae

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

docs/images/img-matrix-9.png

2.45 KB
Loading

docs/matrix.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,34 @@ Here are examples that illustrate some of the achievable effects. All pictures s
220220
.. image:: images/img-matrix-7.*
221221
:scale: 66
222222

223+
9. Show some effects on a rectangle::
223224

225+
import pymupdf
226+
227+
# just definitions and a temp PDF
228+
RED = (1, 0, 0)
229+
BLUE = (0, 0, 1)
230+
GREEN = (0, 1, 0)
231+
doc = pymupdf.open()
232+
page = doc.new_page()
233+
234+
# rectangle
235+
r1 = pymupdf.Rect(100, 100, 200, 200)
236+
237+
# scales down by 50% in x- and up by 50% in y-direction
238+
mat1 = pymupdf.Matrix(0.5, 1.5)
239+
240+
# shifts by 50 in both directions
241+
mat2 = pymupdf.Matrix(1, 0, 0, 1, 50, 50)
242+
243+
# draw corresponding rectangles
244+
page.draw_rect(r1, color=RED) # original
245+
page.draw_rect(r1 * mat1, color=GREEN) # scaled
246+
page.draw_rect(r1 * mat2, color=BLUE) # shifted
247+
doc.ez_save("matrix-effects.pdf")
248+
249+
250+
.. image:: images/img-matrix-9.*
251+
:scale: 66
224252

225253
.. include:: footer.rst

0 commit comments

Comments
 (0)