Spaces:
Sleeping
Sleeping
Update pixelconversion.py
Browse files- pixelconversion.py +13 -24
pixelconversion.py
CHANGED
|
@@ -90,36 +90,26 @@ def openDrawPDF(data,dpi=0):
|
|
| 90 |
|
| 91 |
doc=fitz.open("pdf", data)
|
| 92 |
page = doc[0]
|
| 93 |
-
|
| 94 |
|
| 95 |
if page.rect.height >page.rect.width:
|
| 96 |
rectText=fitz.Rect(300, 200, (page.mediabox.width-80),( page.mediabox.width+80) )
|
| 97 |
else:
|
| 98 |
rectText=fitz.Rect(500, 200, (page.mediabox.height-80),( page.mediabox.height+80) )
|
| 99 |
-
if page.rotation !=0:
|
| 100 |
-
# print('if')
|
| 101 |
-
page.draw_rect([250,250,page.mediabox.width-500,page.mediabox.height-500], color = (75/255,0,130/255), width = 1,fill=(75/255,0,130/255),fill_opacity=0.9 )
|
| 102 |
-
if dpi:
|
| 103 |
-
pix=page.get_pixmap(dpi=dpi)
|
| 104 |
-
newwidth_ratio=pix.width/page.mediabox.width
|
| 105 |
-
newheight_ratio=pix.height/page.mediabox.height
|
| 106 |
-
else:
|
| 107 |
-
newwidth_ratio=1
|
| 108 |
-
newheight_ratio=1
|
| 109 |
-
area=((page.mediabox.height-500-250)*newheight_ratio) * ((page.mediabox.width-500-250)*newwidth_ratio)
|
| 110 |
-
perimeter=(((page.mediabox.width-500-250)*newwidth_ratio)*2) + (((page.mediabox.height-500-250)*newheight_ratio)*2)
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
else:
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
newwidth_ratio=1
|
| 120 |
-
newheight_ratio=1
|
| 121 |
-
area=((page.mediabox.width-10-10)*newwidth_ratio)*((page.mediabox.height-10-10)*newheight_ratio)
|
| 122 |
-
perimeter=(((page.mediabox.width-10-10)*2)*newwidth_ratio)+(((page.mediabox.height-10-10)*2)*newheight_ratio)
|
| 123 |
|
| 124 |
text = """Scale Document"""
|
| 125 |
annot1=page.add_freetext_annot(rectText, text, fontsize=45, fontname='helv', border_color=(1,1,1), text_color=(1,1,1), rotate= page.rotation, align=1)
|
|
@@ -129,4 +119,3 @@ def openDrawPDF(data,dpi=0):
|
|
| 129 |
return doc,area,perimeter
|
| 130 |
"""### Extract color"""
|
| 131 |
|
| 132 |
-
|
|
|
|
| 90 |
|
| 91 |
doc=fitz.open("pdf", data)
|
| 92 |
page = doc[0]
|
| 93 |
+
print('piixelsize',page.mediabox)
|
| 94 |
|
| 95 |
if page.rect.height >page.rect.width:
|
| 96 |
rectText=fitz.Rect(300, 200, (page.mediabox.width-80),( page.mediabox.width+80) )
|
| 97 |
else:
|
| 98 |
rectText=fitz.Rect(500, 200, (page.mediabox.height-80),( page.mediabox.height+80) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
page.draw_rect([0+10,0+10,page.mediabox.width-10,page.mediabox.height-10], color = (75/255,0,130/255), width = 1,fill=(75/255,0,130/255),fill_opacity=0.9 )
|
| 101 |
+
|
| 102 |
+
if dpi:
|
| 103 |
+
pix=page.get_pixmap(dpi=dpi)
|
| 104 |
+
newwidth_ratio=pix.width/page.mediabox.width
|
| 105 |
+
newheight_ratio=pix.height/page.mediabox.height
|
| 106 |
else:
|
| 107 |
+
newwidth_ratio=1
|
| 108 |
+
newheight_ratio=1
|
| 109 |
+
|
| 110 |
+
area=((page.mediabox.width-10-10)*newwidth_ratio)*((page.mediabox.height-10-10)*newheight_ratio)
|
| 111 |
+
perimeter=(((page.mediabox.width-10-10)*2)*newwidth_ratio)+(((page.mediabox.height-10-10)*2)*newheight_ratio)
|
| 112 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
text = """Scale Document"""
|
| 115 |
annot1=page.add_freetext_annot(rectText, text, fontsize=45, fontname='helv', border_color=(1,1,1), text_color=(1,1,1), rotate= page.rotation, align=1)
|
|
|
|
| 119 |
return doc,area,perimeter
|
| 120 |
"""### Extract color"""
|
| 121 |
|
|
|