我想使用有角度的图像滑块制作滑块屏幕。例如,我使用 Laravel 上传图像并将它们保存在 s3 存储桶中,并使用 api 调用使它们以角度滑动,我们可以获取数据。同样,我想使用 PPT 想要上传应该在我的屏幕中滑动的 ppt 文件,并且 ppt 的所有幻灯片都应该像图像一样滑动,这就是流程。我见过很多东西,比如用幻灯片控件显示ppt,就像ms ppt一样,但我想使用ppt幻灯片制作所有自动滑块。 Laravel 或 Angular 中是否有任何方法可以将每张幻灯片拆分为图像或其他内容。
我已经尝试过这样的。
这是我的component.html 文件
<div class="office-viewer">
<iframe [src]='urlSafe' width='100%' height='100%' frameborder='0'></iframe>
</div>
这是我的 component.ts 文件
urlppt: string =
'https://view.officeapps.live.com/op/embed.aspx?src=https://hep-dev.s3.ap-south-1.amazonaws.com/tv-slider-app/samplepptx_a41ed05d0eeb8aac10946c61f4afba17.pptx';
this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(
this.urlppt
);
这里使用iframe来显示页面,只需设置source的urlSafe即可。它将在 Web 中显示整个 ppt,就像 MS Powerpoint 的 Web 视图一样,因为它使用 (https://view.officeapps.live.com/op/embed.aspx?) 查看器。就我而言,我希望所有幻灯片都作为单独的幻灯片,并且它应该像图像滑块一样自动滑动。
有没有办法使用laravel将ppt幻灯片分离成图像。我使用了一种使用 phpoffice/phppresentation 包的方法。
首次安装
composer require phpoffice/phppresentation
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Slide;
public function convertToImages(Request $request)
{
$pptxFile = $request->file('sample.pptx');
$request->validate([
'pptxFile' => 'required|mimetypes:application/vnd.openxmlformats-officedocument.presentationml.presentation'
]);
try {
$presentation = IOFactory::load($pptxFile);
$slides = $presentation->getAllSlides();
dd($slides);
$imageUrls = [];
foreach ($slides as $index => $slide) {
// Convert each slide to an image and save it
$imagePath = 'images/slide_' . ($index + 1) . '.jpg';
$this->saveSlideImage($slide, $imagePath);
$imageUrls[] = asset($imagePath);
}
return response()->json(['images' => $imageUrls]);
} catch (\Exception $e) {
return response()->json(['error' => 'An error occurred during conversion'], 500);
}
}
私有函数 saveSlideImage(幻灯片 $slide, $imagePath) { $thumbnail = $slide->createThumbnail();
if ($thumbnail !== null) {
imagejpeg($thumbnail, public_path($imagePath));
imagedestroy($thumbnail);
}
}
上面的方法会将幻灯片转换为图像并将其保存到路径中。但就我而言,抛出 createThumbnail() 方法是未定义的错误。我该如何解决或有其他方法。