Spaces:
Running
Running
Commit ·
9d9a493
1
Parent(s): 9221bcd
Cover issue
Browse files- package.json +2 -2
- scripts/img2pdf.js +11 -14
- src/Compositions.tsx +6 -16
- src/paperdrive/PaperDriveHorizontalCoverComposition.tsx +1 -0
package.json
CHANGED
|
@@ -16,9 +16,9 @@
|
|
| 16 |
"render-build:igreels": "remotion render --audio-codec mp3 --image-format=jpeg --enable-multi-process-on-linux --quality=70 --concurrency 2 --gl=angle IGReelComposition",
|
| 17 |
"render-build": "remotion render --audio-codec mp3 --image-format=jpeg --enable-multi-process-on-linux --quality=70 --concurrency 2 --gl=angle",
|
| 18 |
"render-still": "remotion still --image-format=jpeg SemibitCompositionPoster ",
|
| 19 |
-
"render-image": "remotion still --image-format=jpeg --concurrency
|
| 20 |
"render-images": "remotion render --enable-multiprocess-on-linux --sequence --image-format=jpeg $npm_config_composition $npm_config_output",
|
| 21 |
-
"paperdrive:pdf": "npm run render-images PaperDriveComposition ./out && node ./scripts/img2pdf.js -o out/pages.pdf",
|
| 22 |
"img2pdf": "node ./scripts/img2pdf.js",
|
| 23 |
"upgrade": "remotion upgrade",
|
| 24 |
"postinstall": "cd node_modules/common-utils && npm run build && cd ../../ && node ffmpeg-fix.js",
|
|
|
|
| 16 |
"render-build:igreels": "remotion render --audio-codec mp3 --image-format=jpeg --enable-multi-process-on-linux --quality=70 --concurrency 2 --gl=angle IGReelComposition",
|
| 17 |
"render-build": "remotion render --audio-codec mp3 --image-format=jpeg --enable-multi-process-on-linux --quality=70 --concurrency 2 --gl=angle",
|
| 18 |
"render-still": "remotion still --image-format=jpeg SemibitCompositionPoster ",
|
| 19 |
+
"render-image": "remotion still --image-format=jpeg --concurrency 4 $npm_config_composition $npm_config_output",
|
| 20 |
"render-images": "remotion render --enable-multiprocess-on-linux --sequence --image-format=jpeg $npm_config_composition $npm_config_output",
|
| 21 |
+
"paperdrive:pdf": "rm out/* && npm run render-images PaperDriveComposition ./out && node ./scripts/img2pdf.js -w 612 -h 792 -o out/pages.pdf && npm run render-image --composition=PaperDriveHorizontalCoverComposition --output=out/cover.jpeg && node ./scripts/img2pdf.js -i out/cover.jpeg -w 1247.516 -h 810 -o out/cover.pdf && rm out/*.jpeg",
|
| 22 |
"img2pdf": "node ./scripts/img2pdf.js",
|
| 23 |
"upgrade": "remotion upgrade",
|
| 24 |
"postinstall": "cd node_modules/common-utils && npm run build && cd ../../ && node ffmpeg-fix.js",
|
scripts/img2pdf.js
CHANGED
|
@@ -5,21 +5,24 @@ import path from 'path';
|
|
| 5 |
const optionDefinitions = [
|
| 6 |
{name: 'output', alias: 'o', type: String},
|
| 7 |
{name: 'input', alias: 'i', type: String},
|
|
|
|
|
|
|
| 8 |
];
|
| 9 |
|
| 10 |
import commandLineArgs from 'command-line-args';
|
| 11 |
const options = commandLineArgs(optionDefinitions);
|
| 12 |
|
| 13 |
const doc = new PDFDocument({
|
| 14 |
-
autoFirstPage: false,
|
| 15 |
});
|
| 16 |
|
| 17 |
const output = options.output || 'out/output.pdf';
|
| 18 |
doc.pipe(fs.createWriteStream(output));
|
| 19 |
|
| 20 |
-
const
|
| 21 |
-
const
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
for (const file of files) {
|
| 25 |
if (
|
|
@@ -27,30 +30,24 @@ for (const file of files) {
|
|
| 27 |
file.endsWith('.png') ||
|
| 28 |
file.endsWith('.jpeg')
|
| 29 |
) {
|
| 30 |
-
const imgPath = path.join(
|
| 31 |
const img = doc.openImage(imgPath);
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
-
// Scale and center the image on the page
|
| 37 |
-
const pageWidth = 612;
|
| 38 |
-
const pageHeight = 792;
|
| 39 |
const imgWidth = img.width;
|
| 40 |
const imgHeight = img.height;
|
| 41 |
|
| 42 |
-
// Calculate scaling to fit the image within the page, preserving aspect ratio
|
| 43 |
const scaleFactor = Math.min(pageWidth / imgWidth, pageHeight / imgHeight);
|
| 44 |
|
| 45 |
-
// Calculate new image dimensions
|
| 46 |
const scaledWidth = imgWidth * scaleFactor;
|
| 47 |
const scaledHeight = imgHeight * scaleFactor;
|
| 48 |
|
| 49 |
-
// Calculate coordinates to center the image
|
| 50 |
const x = (pageWidth - scaledWidth) / 2;
|
| 51 |
const y = (pageHeight - scaledHeight) / 2;
|
| 52 |
|
| 53 |
-
// Add the image to the page, scaled to fit
|
| 54 |
doc.image(imgPath, x, y, {width: scaledWidth, height: scaledHeight});
|
| 55 |
}
|
| 56 |
}
|
|
|
|
| 5 |
const optionDefinitions = [
|
| 6 |
{name: 'output', alias: 'o', type: String},
|
| 7 |
{name: 'input', alias: 'i', type: String},
|
| 8 |
+
{name: 'width', alias: 'w', type: Number},
|
| 9 |
+
{name: 'height', alias: 'h', type: Number},
|
| 10 |
];
|
| 11 |
|
| 12 |
import commandLineArgs from 'command-line-args';
|
| 13 |
const options = commandLineArgs(optionDefinitions);
|
| 14 |
|
| 15 |
const doc = new PDFDocument({
|
| 16 |
+
autoFirstPage: false,
|
| 17 |
});
|
| 18 |
|
| 19 |
const output = options.output || 'out/output.pdf';
|
| 20 |
doc.pipe(fs.createWriteStream(output));
|
| 21 |
|
| 22 |
+
const input = options.input || 'out';
|
| 23 |
+
const isFolder = fs.lstatSync(input).isDirectory();
|
| 24 |
+
const files = isFolder ? fs.readdirSync(input) : [input];
|
| 25 |
+
console.log('Reading', files.length, 'from', input, '... ');
|
| 26 |
|
| 27 |
for (const file of files) {
|
| 28 |
if (
|
|
|
|
| 30 |
file.endsWith('.png') ||
|
| 31 |
file.endsWith('.jpeg')
|
| 32 |
) {
|
| 33 |
+
const imgPath = isFolder ? path.join(input, file) : file;
|
| 34 |
const img = doc.openImage(imgPath);
|
| 35 |
|
| 36 |
+
const pageWidth = options.width || 612;
|
| 37 |
+
const pageHeight = options.height || 792;
|
| 38 |
+
doc.addPage({size: [pageWidth, pageHeight], margin: 0});
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
const imgWidth = img.width;
|
| 41 |
const imgHeight = img.height;
|
| 42 |
|
|
|
|
| 43 |
const scaleFactor = Math.min(pageWidth / imgWidth, pageHeight / imgHeight);
|
| 44 |
|
|
|
|
| 45 |
const scaledWidth = imgWidth * scaleFactor;
|
| 46 |
const scaledHeight = imgHeight * scaleFactor;
|
| 47 |
|
|
|
|
| 48 |
const x = (pageWidth - scaledWidth) / 2;
|
| 49 |
const y = (pageHeight - scaledHeight) / 2;
|
| 50 |
|
|
|
|
| 51 |
doc.image(imgPath, x, y, {width: scaledWidth, height: scaledHeight});
|
| 52 |
}
|
| 53 |
}
|
src/Compositions.tsx
CHANGED
|
@@ -199,31 +199,21 @@ export const Compositions: React.FC = () => {
|
|
| 199 |
<Composition
|
| 200 |
id='PaperDriveComposition'
|
| 201 |
component={PaperDriveComposition}
|
| 202 |
-
durationInFrames={Script.meta.fps * Script.transcript.length}
|
| 203 |
fps={fps}
|
| 204 |
width={Script.meta?.resolution?.width || 1920}
|
| 205 |
height={Script.meta?.resolution?.height || 1080}
|
| 206 |
-
defaultProps={Object.assign(Script
|
| 207 |
-
bgMusic: RenderUtils.getFileName(Script.bgMusic, "mp3"),
|
| 208 |
-
contents: contents,
|
| 209 |
-
intro: intro,
|
| 210 |
-
outro: outro
|
| 211 |
-
})}
|
| 212 |
/>
|
| 213 |
|
| 214 |
<Composition
|
| 215 |
id='PaperDriveHorizontalCoverComposition'
|
| 216 |
component={PaperDriveHorizontalCoverComposition}
|
| 217 |
-
durationInFrames={
|
| 218 |
fps={fps}
|
| 219 |
-
height={
|
| 220 |
-
width={
|
| 221 |
-
defaultProps={Object.assign(Script
|
| 222 |
-
bgMusic: RenderUtils.getFileName(Script.bgMusic, "mp3"),
|
| 223 |
-
contents: contents,
|
| 224 |
-
intro: intro,
|
| 225 |
-
outro: outro
|
| 226 |
-
})}
|
| 227 |
/>
|
| 228 |
<Composition
|
| 229 |
defaultProps={{
|
|
|
|
| 199 |
<Composition
|
| 200 |
id='PaperDriveComposition'
|
| 201 |
component={PaperDriveComposition}
|
| 202 |
+
durationInFrames={Script.meta.fps * Script.transcript.filter(transcript => ['index', 'page'].includes(transcript.extras?.template)).length}
|
| 203 |
fps={fps}
|
| 204 |
width={Script.meta?.resolution?.width || 1920}
|
| 205 |
height={Script.meta?.resolution?.height || 1080}
|
| 206 |
+
defaultProps={Object.assign(Script)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
/>
|
| 208 |
|
| 209 |
<Composition
|
| 210 |
id='PaperDriveHorizontalCoverComposition'
|
| 211 |
component={PaperDriveHorizontalCoverComposition}
|
| 212 |
+
durationInFrames={1}
|
| 213 |
fps={fps}
|
| 214 |
+
height={parseInt(`${810 * 1.5}`)}
|
| 215 |
+
width={parseInt(`${1247.016 * 1.5}`)}
|
| 216 |
+
defaultProps={Object.assign(Script)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
/>
|
| 218 |
<Composition
|
| 219 |
defaultProps={{
|
src/paperdrive/PaperDriveHorizontalCoverComposition.tsx
CHANGED
|
@@ -11,6 +11,7 @@ export const PaperDriveHorizontalCoverComposition = (props: OriginalManuscript)
|
|
| 11 |
const data = props.transcript
|
| 12 |
.filter(v => ["front-cover", "back-cover"].includes(v.extras?.template))
|
| 13 |
|
|
|
|
| 14 |
const frontData = data[0]
|
| 15 |
const backData = data[1]
|
| 16 |
|
|
|
|
| 11 |
const data = props.transcript
|
| 12 |
.filter(v => ["front-cover", "back-cover"].includes(v.extras?.template))
|
| 13 |
|
| 14 |
+
|
| 15 |
const frontData = data[0]
|
| 16 |
const backData = data[1]
|
| 17 |
|