I am currently working on a project where I need to convert PPT/PPTX files to Markdown format using the Aspose Python API. One of the requirements is to extract the coordinates (position and dimensions) of any images embedded in the slides.
I have successfully managed to convert the PPT/PPTX files to Markdown, but I am struggling to find a way to extract the exact coordinates of the images. I need this information to properly position the images in the Markdown output.
![Image](./Images/Image_2.png)
Could someone please guide me on how to achieve this using the Aspose Python API? I am looking for a method or property that allows me to retrieve the position (x, y) and dimensions (width, height) of images within the slides.
Thank you in advance for your help!
To extract the coordinates (position and dimensions) of images embedded in PPT/PPTX slides while converting them to Markdown using the Aspose Python API, you can utilize the Slide and Shape classes provided by the library. Here’s a step-by-step guide on how to achieve this:
Load the Presentation: First, load your PPT/PPTX file using the Presentation class.
Iterate Through Slides: Loop through each slide in the presentation.
Access Shapes: For each slide, access the shapes and check if they are images.
Retrieve Coordinates and Dimensions: For each image shape, you can retrieve its position (x, y) and dimensions (width, height).
Here’s a sample code snippet demonstrating this process:
import aspose.slides as slides
# Load the presentation
presentation = slides.Presentation("your_presentation.pptx")
# Iterate through each slide
for slide_index, slide in enumerate(presentation.slides):
# Iterate through each shape in the slide
for shape in slide.shapes:
# Check if the shape is an image
if shape.shape_type == slides.ShapeType.Picture:
# Get the position and dimensions
x = shape.x
y = shape.y
width = shape.width
height = shape.height
# Print or store the coordinates and dimensions
print(f"Slide {slide_index + 1}: Image at ({x}, {y}) with size ({width}, {height})")
Explanation:
The shape.x and shape.y properties give you the coordinates of the image.
The shape.width and shape.height properties provide the dimensions of the image.
You can modify the code to store these values in a list or any other structure as needed for your Markdown output.
This approach will help you extract the necessary information to position images correctly in your Markdown format. If you have any further questions or need additional assistance, feel free to ask!
@andrey.potapov hello, I can get image coordinates and size of image(png/jpg/jepg…) from ppt/pptx file, my function like
def get_shape(shape):
shape_lst = []
if type(shape) is slides.AutoShape and shape.fill_format.fill_type == slides.FillType.PICTURE:
elif type(shape) is slides.PictureFrame:
shape_lst.append(shape)
else:
pass
return shape_lst
However, it seems that the function is unable to fetch the coordinates and dimensions of SVG vector images. I would appreciate any guidance on how to modify the code to accommodate SVG images.
@kyrieqi,
Unfortunately, I was unable to reproduce the problem you described. Could you please share a sample presentation file and complete code example to reproduce the problem?