Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to center an image? #103

Open
domindez opened this issue Nov 5, 2022 · 1 comment
Open

Is it possible to center an image? #103

domindez opened this issue Nov 5, 2022 · 1 comment

Comments

@domindez
Copy link

domindez commented Nov 5, 2022

Hi! Is it possible to center an image horizontally in the slide?

@MaoHuPi
Copy link

MaoHuPi commented Apr 7, 2023

You can use "layout" to get the width and height of slide to center an image.

Although I don't know exactly what the numerical unit in the original setting is, at least I found a constant that can calculate its actual length.

code:

function centerImage(imageRect = {x: 0, y: 0, cx: 10, cy: 10}, direction = 'horizontal', layout = 'LAYOUT_16x9'){
    let layouts = {
        LAYOUT_4x3: { type: 'screen4x3', width: 9144000, height: 6858000 },
        LAYOUT_16x9: { type: 'screen16x9', width: 9144000, height: 5143500 },
        LAYOUT_16x10: { type: 'screen16x10', width: 9144000, height: 5715000 },
        LAYOUT_WIDE: { type: 'custom', width: 12191996, height: 6858000 },
        LAYOUT_USER: { type: 'custom', width: 12191996, height: 6858000 },
    };
    let lengthRatio = 1/1e4/32.24*25.4;
    let slideWidth = layouts[layout].width*lengthRatio;
    let slideHeight = layouts[layout].height*lengthRatio;
    if(['horizontal', 'both'].indexOf(direction) > -1) imageRect.x = (slideWidth - imageRect.cx)/2;
    if(['vertical', 'both'].indexOf(direction) > -1) imageRect.y = (slideHeight - imageRect.cy)/2;
    return(imageRect);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants