fix(baoyu-slide-deck): add pptxgenjs dependency and detect image format by magic bytes
This commit is contained in:
parent
4821508c34
commit
ae1d619ab2
|
|
@ -17,6 +17,7 @@
|
||||||
"tsx": "^4.20.5"
|
"tsx": "^4.20.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pdf-lib": "^1.17.1"
|
"pdf-lib": "^1.17.1",
|
||||||
|
"pptxgenjs": "^4.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,8 @@ async function createPdf(slides: SlideInfo[], outputPath: string) {
|
||||||
|
|
||||||
for (const slide of slides) {
|
for (const slide of slides) {
|
||||||
const imageData = readFileSync(slide.path);
|
const imageData = readFileSync(slide.path);
|
||||||
const ext = slide.filename.toLowerCase();
|
const isPng = imageData[0] === 0x89 && imageData[1] === 0x50 && imageData[2] === 0x4e && imageData[3] === 0x47;
|
||||||
const image = ext.endsWith(".png")
|
const image = isPng
|
||||||
? await pdfDoc.embedPng(imageData)
|
? await pdfDoc.embedPng(imageData)
|
||||||
: await pdfDoc.embedJpg(imageData);
|
: await pdfDoc.embedJpg(imageData);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue