MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / ppt_to_images

Function ppt_to_images

utils/src/utils.py:140–178  ·  view source on GitHub ↗
(file: str, output_dir: str, warning: bool = False, dpi=72, output_type='png')

Source from the content-addressed store, hash-verified

138
139@tenacity
140def ppt_to_images(file: str, output_dir: str, warning: bool = False, dpi=72, output_type='png'):
141 assert pexists(file), f"File {file} does not exist"
142 if pexists(output_dir) and warning:
143 print(f"ppt2images: {output_dir} already exists")
144 os.makedirs(output_dir, exist_ok=True)
145 with tempfile.TemporaryDirectory() as temp_dir:
146 # Create unique user installation directory for LibreOffice to avoid concurrency issues
147 with tempfile.TemporaryDirectory() as user_install_dir:
148 command_list = [
149 "soffice",
150 "--headless",
151 "--norestore",
152 "--nolockcheck",
153 f"-env:UserInstallation=file://{user_install_dir}",
154 "--convert-to",
155 "pdf",
156 file,
157 "--outdir",
158 temp_dir,
159 ]
160 # Set environment to ensure UTF-8 encoding
161 env = os.environ.copy()
162 env['LC_ALL'] = 'en_US.UTF-8'
163 env['LANG'] = 'en_US.UTF-8'
164 subprocess.run(command_list, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=env)
165
166 for f in os.listdir(temp_dir):
167 if not f.endswith(".pdf"):
168 continue
169 temp_pdf = pjoin(temp_dir, f)
170 images = convert_from_path(temp_pdf, dpi=72)
171 for i, img in enumerate(images):
172 if output_type == 'png':
173 img.save(pjoin(output_dir, f"poster.png"), 'PNG')
174 else:
175 img.save(pjoin(output_dir, f"poster.jpg"), 'JPEG')
176 return
177
178 raise RuntimeError("No PDF file was created in the temporary directory", file)
179
180
181@tenacity

Callers 14

generate_slidesFunction · 0.90
prepare_ppt_folderFunction · 0.90
pptx2imagesFunction · 0.90
kctv_gen_pptFunction · 0.90
render_textboxFunction · 0.90
gen_outline_layoutFunction · 0.90
fill_poster_contentFunction · 0.90
stylize_posterFunction · 0.90
poster_apply_themeFunction · 0.90
deoverflowFunction · 0.90
gen_outline_layoutFunction · 0.90

Calls 3

copyMethod · 0.45
runMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected