Skip to content

Commit

Permalink
fix: 导出PPT时判断图片引用类型(#251
Browse files Browse the repository at this point in the history
  • Loading branch information
pipipi-pikachu committed Feb 4, 2024
1 parent 4e8832f commit 32d1601
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/hooks/useExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 32d1601

Please sign in to comment.