Closed Bruce337f closed 8 months ago
Well, md2pptx isn't a general CSS parser.
I'm not entirely sure I understand the problem. It seems to me you want an image pan and zoom capability within a fixed composing area.
If that is the case there are two problems to solve:
Right now what md2pptx does is to scale the image to meet the composing space it's allowed.
One possibility - which ignores Problem 1 - is to have a metadata item that says how the graphic should behave. It would still leave Problem 2 and quite a lot of code would be needed.
Further to that idea, it could be "dynamic metadata", meaning you could set it at any point for all subsequent slides.
But, still, the main problem is how to tweak the XML so that Powerpoint shows the behaviour.
Looks like a very cumbersome piece of functionality and I will try other methods to maintain the ability to have image pan and zoom within a fixed composition area. Perhaps affected by xml, this function block cannot be implemented as accurately as css.
This is a good project, thank you for your prompt reply!
The main thing that makes me curious is that text, video and audio all support CSS and can support a wider range of CSS formats. Is it because python-pptx does not support image processing, or does XML require a lot of re-development of code when processing images?
This is a great project! ! ``
Thanks for your kind words.
The CSS support you see in md2pptx is actually in my parser, not python-pptx. It is very limited and its purpose today is to support colours when rendered by other Markdown processors. Supporting more CSS is possible - but not as complex as the fragment you've shown.
I'm more optimistic than you about panning and zooming...
... If you can demonstrate that a .pptx can contain this functionality without resorting to VBA it's highly likely the necessary XML can be crafted by md2pptx. So please try to create an example - and add here instructions to recreate.
If we get that far I think we can do this with a metadata item. And if md2pptx can do it with metadata it could certainly do it with dynamic metadata. The implications of that are one slide could pan and zoom and others could scale.
Thanks for your reply, it allowed me to look at the problem in a new way! For example, this pptx page contains image background, image content and text:
I want to achieve what is shown in this ppt, such as juxtaposing images and text, filling the background color with images in different positions, etc.,
The metadata might be too complex for me, I'm a noob at this and looking forward to your performance.
I know that AI can generate pptx about the theme you want, but the pictures and backgrounds are too free. For me, this project can generate pptx in a fixed format,
This is a good project!
`from pptx import Presentation from pptx.util import Inches
def move_and_scale_image(prs, slide_index, image_index, left, top, width, height): slide = prs.slides[slide_index] shapes = slide.shapes image = shapes[image_index].image image.left = Inches(left) image.top = Inches(top) image.width = Inches(width) image.height = Inches(height)
if name == "main": presentation = Presentation() slide = presentation.slides.add_slide(presentation.slide_layouts[0]) image_path = "path/to/your/image.jpg" left, top, width, height = 1, 1, 4, 3 寸 picture = slide.shapes.add_picture(image_path, Inches(left), Inches(top), width=Inches(width), height=Inches(height)) move_and_scale_image(presentation, 0, 0, 2, 2, 3, 2) presentation.save("output.pptx") ` This is the code it gave after asking ai. I think it is too crude.
So the image background normally comes from the template pptx. Unless you mean a different image on every slide. md2pptx doesn't add background images.
The code you posted - with interesting comments 😃 - just creates a static picture on a slide (if it even works).
Maybe you don't want pan and zoom after all.
I did a little research and it doesn't look like Powerpoint has a pan and zoom capability. Its only option for images is scaling.
Sorry, it may be that machine translation caused the reply to misunderstand you. This is just a solution given by AI. It does not implement the panning and zooming functions. In short, it is just an invalid code.
So the image background normally comes from the template pptx. Unless you mean a different image on every slide. md2pptx doesn't add background images.
The code you posted - with interesting comments 😃 - just creates a static picture on a slide (if it even works).
Maybe you don't want pan and zoom after all.
I feel that the functions implemented by python-pptx are much less than the normal use of pptx. However, if it is just image scaling, the juxtaposition and fusion of images content and text content seem to be impossible to achieve.
I did a little research and it doesn't look like Powerpoint has a pan and zoom capability. Its only option for images is scaling.
Thanks for your reply, this is a great project! !
Thanks for your reply, it allowed me to look at the problem in a new way! For example, this pptx page contains image background, image content and text:
I want to achieve what is shown in this ppt, such as juxtaposing images and text, filling the background color with images in different positions, etc.,
The metadata might be too complex for me, I'm a noob at this and looking forward to your performance.
I know that AI can generate pptx about the theme you want, but the pictures and backgrounds are too free. For me, this project can generate pptx in a fixed format,
This is a good project!
Can the current version of standard Markdown fully reproduce all the visual effects on this PowerPoint page, or achieve a side-by-side arrangement of left-text content and right-image content? Or is it only possible to simply paste images into the PowerPoint, with the text content remaining invisible?
Dealing with images in python-pptx seems to be challenging!
By the way, could you please explain how the template determines different background colors and themes for each slide in the generated pptx? Is it random? Also, it would be great if the code could be packaged as a Python package.
This is a fantastic project!
Several things here:
Markdown doesn't have a standard way of doing a background. md2pptx could add one - as it's just an image. If you need that open an issue. The mechanism for page-by-page background images would be (dynamic) metadata. Whether this is just an image composed onto the page or a true background depends on research into the XML.
I've had the request for a package before. I'll have to think about how to do it.
On the "colours" question, it's in the theme the template uses. And where they are used are again down to how the template is set up. Choose / make your template carefully. For example, the built in template for python-pptx is not very modern. The example one in md2pptx is much better, in my opinion.
Thanks for your reply,
I'm more concerned about the ability to have images and text coexist on the same page in Markdown, similar to the title text shown above and the child on the right in the image. However, in md2pptx, I can only use , and it takes up a whole PowerPoint slide without displaying any text.
I'm looking forward to your new CSS for image handling, if possible.
For projects that require fixed-format PPTX generation, this is a great initiative!
Thank you for considering this.
For example: the image with the general characters on the right side and middle, and the unenclosed image covered? I have tried by using HTML and CSS to create a container with images and text, and using CSS styles to set the layout, but it doesn't work, any suggestions? div style="display: flex; align-items: center;"> img src="image.jpg" alt="img" style="max-width: 50%; margin-right: 20px;" div> p>text
/div> /div>