From 32d1601830a46d1653a09b571d1e5a4ab8267f30 Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Sun, 4 Feb 2024 22:24:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=BC=E5=87=BAPPT=E6=97=B6=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E5=9B=BE=E7=89=87=E5=BC=95=E7=94=A8=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=EF=BC=88#251=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useExport.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/hooks/useExport.ts b/src/hooks/useExport.ts index 5248a39c8..8a8b2143e 100644 --- a/src/hooks/useExport.ts +++ b/src/hooks/useExport.ts @@ -352,6 +352,12 @@ export default () => { return null } + // 判断是否为Base64图片地址 + const isBase64Image = (url: string) => { + const regex = /^data:image\/[^;]+;base64,/ + return url.match(regex) !== null + } + // 导出PPTX文件 const exportPPTX = (_slides: Slide[], masterOverwrite: boolean, ignoreMedia: boolean) => { exporting.value = true @@ -383,7 +389,8 @@ export default () => { if (slide.background) { const background = slide.background if (background.type === 'image' && background.image) { - pptxSlide.background = { data: background.image } + if (isBase64Image(background.image)) pptxSlide.background = { data: background.image } + else pptxSlide.background = { path: background.image } } else if (background.type === 'solid' && background.color) { const c = formatColor(background.color) @@ -439,12 +446,14 @@ export default () => { else if (el.type === 'image') { const options: pptxgen.ImageProps = { - path: el.src, x: el.left / INCH_PX_RATIO, y: el.top / INCH_PX_RATIO, w: el.width / INCH_PX_RATIO, h: el.height / INCH_PX_RATIO, } + if (isBase64Image(el.src)) options.data = el.src + else options.path = el.src + if (el.flipH) options.flipH = el.flipH if (el.flipV) options.flipV = el.flipV if (el.rotate) options.rotate = el.rotate