Update
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// utils/timeline-template-processor.js
|
||||
|
||||
export const generateTimelineFromTemplate = (template, mediaStoreData) => {
|
||||
export const generateTimelineFromTemplate = (dimensions, template, mediaStoreData) => {
|
||||
const { selectedMeme, selectedBackground, currentCaption } = mediaStoreData;
|
||||
|
||||
// If no selections, return empty timeline
|
||||
@@ -28,6 +28,32 @@ export const generateTimelineFromTemplate = (template, mediaStoreData) => {
|
||||
if (selectedBackground) {
|
||||
processedElement.source = selectedBackground.media_url;
|
||||
processedElement.name = selectedBackground.prompt || 'Background';
|
||||
processedElement.media_width = selectedBackground.media_width;
|
||||
processedElement.media_height = selectedBackground.media_height;
|
||||
|
||||
const canvasWidth = dimensions.width;
|
||||
const canvasHeight = dimensions.height;
|
||||
|
||||
// Calculate scale factors to fit media within canvas while maintaining aspect ratio
|
||||
const scaleX = canvasWidth / selectedBackground.media_width;
|
||||
const scaleY = canvasHeight / selectedBackground.media_height;
|
||||
|
||||
// Use the larger scale factor to ensure the media fills the entire canvas
|
||||
const scale = Math.max(scaleX, scaleY);
|
||||
|
||||
// Calculate final dimensions
|
||||
const scaledWidth = selectedBackground.media_width * scale;
|
||||
const scaledHeight = selectedBackground.media_height * scale;
|
||||
|
||||
// Center the scaled media within the canvas
|
||||
const offsetX = (canvasWidth - scaledWidth) / 2;
|
||||
const offsetY = (canvasHeight - scaledHeight) / 2;
|
||||
|
||||
// Set the processed element properties
|
||||
processedElement.width = scaledWidth;
|
||||
processedElement.height = scaledHeight;
|
||||
processedElement.x = offsetX;
|
||||
processedElement.y = offsetY;
|
||||
} else {
|
||||
return null; // Skip if no background selected
|
||||
}
|
||||
@@ -39,6 +65,10 @@ export const generateTimelineFromTemplate = (template, mediaStoreData) => {
|
||||
processedElement.source_mov = selectedMeme.mov_url;
|
||||
processedElement.poster = selectedMeme.webp_url;
|
||||
processedElement.name = selectedMeme.name;
|
||||
processedElement.media_width = selectedMeme.media_width;
|
||||
processedElement.media_height = selectedMeme.media_height;
|
||||
processedElement.width = selectedMeme.media_width;
|
||||
processedElement.height = selectedMeme.media_height;
|
||||
} else {
|
||||
return null; // Skip if no meme selected
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user