ppt function to replace images

This commit is contained in:
2026-01-29 15:36:34 +01:00
parent bc12df28a5
commit 3ee25f9e33
6 changed files with 326 additions and 96 deletions

63
03_ppt_replace_images.py Normal file
View File

@@ -0,0 +1,63 @@
import marimo
__generated_with = "0.19.2"
app = marimo.App(width="medium")
with app.setup:
import marimo as mo
from pathlib import Path
import utils
@app.cell
def _():
PPT_FILE = Path('data/Presentation.pptx')
UPDATED_PPT_FILE = Path('data/Updated_Presentation.pptx')
return PPT_FILE, UPDATED_PPT_FILE
@app.cell
def _():
IMAGE_FILE = Path('figures/OneDrive_2026-01-28/Cons-Early_Professional/cold_distant_approachable_familiar_warm.png')
return (IMAGE_FILE,)
@app.function
def image_alt_text_converter(fpath):
"""convert image file path to alt text
"""
if not isinstance(fpath, Path):
fpath = Path(fpath)
fparts = fpath.parts
assert fparts[0] == 'figures', "Image file path must start with 'figures'"
return Path('/'.join(fparts[2:])).as_posix()
@app.cell
def _(IMAGE_FILE):
img_alt_txt = image_alt_text_converter(IMAGE_FILE)
img_alt_txt
return (img_alt_txt,)
@app.cell
def _(IMAGE_FILE, PPT_FILE, UPDATED_PPT_FILE, img_alt_txt):
utils.pptx_replace_named_image(
presentation_path=PPT_FILE,
target_tag=img_alt_txt,
new_image_path=IMAGE_FILE,
save_path=UPDATED_PPT_FILE)
return
@app.cell
def _(P):
print(P.slides[10])
return
if __name__ == "__main__":
app.run()