Scale a Quad from center in all directions #1090
-
I'm searching for text in a pdf and extracting a quad and adding a polygon_annot around it. Below is my code: for inst in text_instances:
inst = inst.transform(fitz.Matrix(2, 2))
print(inst)
print(inst.rect)
# re-ordering the points in list counter-clockwise
inst[2], inst[3] = inst[3], inst[2]
highlight = page.add_polygon_annot(inst) i'm currently scaling it with |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
You can simply first add the annot. |
Beta Was this translation helpful? Give feedback.
-
Manipulating the annot's rect also needs no use of |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Thank you for your response @JorjMcKie. But I found that you can use Below is the function that i'm using to scale the morph by its center: def getPolygon(inst, scale=1):
[sumX, sumY] = [0, 0]
for point in inst:
sumX += point[0]
sumY += point[1]
avgX = sumX/4
avgY = sumY/4
# Scale the rectange using Quad.morph(): https://pymupdf.readthedocs.io/en/latest/quad.html#Quad.morph
inst = inst.morph(fitz.Point(avgX, avgY), fitz.Matrix(scale, scale))
# re-ordering the points in list counter-clockwise
inst[2], inst[3] = inst[3], inst[2]
return inst |
Beta Was this translation helpful? Give feedback.
Thank you for your response @JorjMcKie. But I found that you can use
morph
to scale the quadBelow is the function that i'm using to scale the morph by its center: