Spaces:
Sleeping
Sleeping
Update pptx2png.py
Browse files- pptx2png.py +16 -0
pptx2png.py
CHANGED
|
@@ -2,6 +2,7 @@ import io
|
|
| 2 |
from pptx import Presentation
|
| 3 |
from pptx.enum.shapes import MSO_SHAPE_TYPE
|
| 4 |
from pptx.enum.text import PP_ALIGN
|
|
|
|
| 5 |
from PIL import Image, ImageDraw, ImageFont
|
| 6 |
import skia
|
| 7 |
|
|
@@ -84,6 +85,21 @@ def pptx_to_images(pptx_path):
|
|
| 84 |
font_size = int(font_info['size'] / EMU_TO_POINTS) # Convert EMUs to points
|
| 85 |
font = ImageFont.truetype("fonts/FXZK-FANXMLT.ttf", font_size)
|
| 86 |
# font = ImageFont.truetype(font_info['name'], font_info['size'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
draw.text((text_left, text_top), paragraph_item['text'], fill=font_info['color'], font=font)
|
| 88 |
elif shape.shape_type == MSO_SHAPE_TYPE.PICTURE:
|
| 89 |
# Convert shape position and size from EMUs to pixels
|
|
|
|
| 2 |
from pptx import Presentation
|
| 3 |
from pptx.enum.shapes import MSO_SHAPE_TYPE
|
| 4 |
from pptx.enum.text import PP_ALIGN
|
| 5 |
+
from pptx.shapes.group import GroupShape
|
| 6 |
from PIL import Image, ImageDraw, ImageFont
|
| 7 |
import skia
|
| 8 |
|
|
|
|
| 85 |
font_size = int(font_info['size'] / EMU_TO_POINTS) # Convert EMUs to points
|
| 86 |
font = ImageFont.truetype("fonts/FXZK-FANXMLT.ttf", font_size)
|
| 87 |
# font = ImageFont.truetype(font_info['name'], font_info['size'])
|
| 88 |
+
|
| 89 |
+
# Calculate text bounding box
|
| 90 |
+
bbox = draw.textbbox((0, 0), paragraph_item['text'], font=font)
|
| 91 |
+
text_width = bbox[2] - bbox[0]
|
| 92 |
+
text_height = bbox[3] - bbox[1]
|
| 93 |
+
|
| 94 |
+
# Adjust text position based on alignment
|
| 95 |
+
if paragraph_item['align'] == PP_ALIGN.LEFT:
|
| 96 |
+
text_left = text_left
|
| 97 |
+
elif paragraph_item['align'] == PP_ALIGN.CENTER:
|
| 98 |
+
text_left = text_left + (shape.width / EMU_TO_PIXELS - text_width) / 2
|
| 99 |
+
elif paragraph_item['align'] == PP_ALIGN.RIGHT:
|
| 100 |
+
text_left = text_left + shape.width / EMU_TO_PIXELS - text_width
|
| 101 |
+
else:
|
| 102 |
+
text_left = text_left
|
| 103 |
draw.text((text_left, text_top), paragraph_item['text'], fill=font_info['color'], font=font)
|
| 104 |
elif shape.shape_type == MSO_SHAPE_TYPE.PICTURE:
|
| 105 |
# Convert shape position and size from EMUs to pixels
|