Revert "Update"

This reverts commit 1282400372.
This commit is contained in:
ct
2025-06-16 13:52:41 +08:00
parent 5dec236a1f
commit 471e7e1cd4

View File

@@ -197,51 +197,35 @@ const VideoEditor = ({ width, height }) => {
posterImg.onload = () => { posterImg.onload = () => {
console.log('Poster loaded for:', element.id); console.log('Poster loaded for:', element.id);
const canvasWidth = dimensions.width; const maxWidth = dimensions.width;
const canvasHeight = dimensions.height; const maxHeight = dimensions.height;
const imageWidth = posterImg.naturalWidth; const posterWidth = posterImg.naturalWidth;
const imageHeight = posterImg.naturalHeight; const posterHeight = posterImg.naturalHeight;
// Calculate aspect ratios let scaledWidth = posterWidth;
const canvasAspect = canvasWidth / canvasHeight; let scaledHeight = posterHeight;
const imageAspect = imageWidth / imageHeight;
let scaledWidth, scaledHeight, centeredX, centeredY; if (posterWidth > maxWidth || posterHeight > maxHeight) {
const scaleX = maxWidth / posterWidth;
const scaleY = maxHeight / posterHeight;
const scale = Math.min(scaleX, scaleY);
scaledWidth = posterWidth * scale;
scaledHeight = posterHeight * scale;
}
// ✅ UPDATED: Different positioning for background vs meme
let centeredX, centeredY;
if (element.id.startsWith('bg_')) { if (element.id.startsWith('bg_')) {
// Background: Cover behavior - fill entire canvas, crop if needed // Background should fill the canvas
if (imageAspect > canvasAspect) {
// Image is wider than canvas - fit height, crop width
scaledHeight = canvasHeight;
scaledWidth = scaledHeight * imageAspect;
centeredX = (canvasWidth - scaledWidth) / 2; // Center horizontally
centeredY = 0;
} else {
// Image is taller than canvas - fit width, crop height
scaledWidth = canvasWidth;
scaledHeight = scaledWidth / imageAspect;
centeredX = 0; centeredX = 0;
centeredY = (canvasHeight - scaledHeight) / 2; // Center vertically centeredY = 0;
} scaledWidth = maxWidth;
scaledHeight = maxHeight;
} else { } else {
// Meme overlay: Cover behavior but with some padding/sizing // Meme should be centered
const memeMaxWidth = canvasWidth; // 100% of canvas width centeredX = (maxWidth - scaledWidth) / 2;
const memeMaxHeight = canvasHeight; // 100% of canvas height centeredY = (maxHeight - scaledHeight) / 2;
const memeAspect = memeMaxWidth / memeMaxHeight;
if (imageAspect > memeAspect) {
// Image is wider - fit height, crop width
scaledHeight = memeMaxHeight;
scaledWidth = scaledHeight * imageAspect;
} else {
// Image is taller - fit width, crop height
scaledWidth = memeMaxWidth;
scaledHeight = scaledWidth / imageAspect;
}
// Center the meme on canvas
centeredX = (canvasWidth - scaledWidth) / 2;
centeredY = (canvasHeight - scaledHeight) / 2;
} }
setTimelineElements((prev) => setTimelineElements((prev) =>