使用Applescript最大化Powerpoint中的图像大小调整

时间:2012-09-29 20:27:12

标签: image resize applescript powerpoint

我在Macbook上使用MS Powerpoint 2008。我已经使用提供的Automator操作将一堆图像(100左右)添加到新的PPTX文件中。图像居中,但它们并未完全最大化。可以使用的边缘周围有大约0.5-1英寸的空间。我更喜欢垂直或水平最大化的图像,或者适合图像的图像。

知道如何添加代码来确定图像(形状)是否最好最大化到幻灯片高度(7.5英寸x 72像素/英寸)或宽度(10英寸或720像素)?

到目前为止,这是我的代码:

tell application "Microsoft PowerPoint"
    activate
    set thePres to active presentation
    set slideCount to count slides of thePres
        repeat with a from 1 to slideCount
        set theShape to first shape of slide a of thePres
        set height of theShape to (7.5 * 70)
        set leftPos to (slide width of page setup of thePres) - (width of theShape)
        set left position of theShape to (leftPos / 2)
        set top of theShape to 0
    end repeat
end tell

这是我在实施建议后更新的代码。我必须添加一行来检查在图像宽度大于高度的情况下调整大小后高度是否超过幻灯片高度,但是与幻灯片中的7.5 x 10的比率不同:

tell application "Microsoft PowerPoint"
    activate
    set thePres to active presentation
    set slideCount to count slides of thePres
    repeat with a from 1 to slideCount
        set theShape to first shape of slide a of thePres
        if height of theShape is greater than width of theShape then
            set height of theShape to (7.5 * 72)
        else
            set width of theShape to (10 * 72)
        end if
        if height of theShape is greater than 540 then
            set height of theShape to 540
        end if
        set leftPos to (slide width of page setup of thePres) - (width of theShape)
        set left position of theShape to (leftPos / 2)
        set top of theShape to 0
    end repeat
end tell

1 个答案:

答案 0 :(得分:1)

首先,为什么“将形状的高度设置为(7.5 * 70)”?

默认滑动高度为7.5 * 72(7.5英寸*每英寸72点)

假设图像已经添加到幻灯片中,您需要查看图像的宽度除以高度。如果结果为1或更小,则图像为方形或高于宽度,因此您需要将其垂直居中。如果它> 1,则将其水平居中。