【问题标题】:InDesign script, resize images after word importInDesign 脚本,在文字导入后调整图像大小
【发布时间】:2020-03-20 17:32:38
【问题描述】:

有时我们在 word 文件中有大图像,在 InDesign 中导入这个 word 文件后,图像进入溢出文本,此时文本流停止。

我们无法调整这些图像的大小,或者无法获取该图像以应用任何脚本逻辑。

基本上,我将搜索图形 parastyle,然后检查 para 内的矩形,并执行调整大小的逻辑。此处的示例 jsx 代码:

app.findTextPreferences.appliedParagraphStyle= 'figure';
var founds = app.findText();

// find 92% text width area
var pageWidth = this.props.textAreaWidth * 92 /100;
for(var i=0, len=founds.length; i<len; i++){
    // find the rectangles inside the para
    var rect = founds[i].rectangles;
    if(rect.length == 0) continue;
    var vb = rect[0].visibleBounds;
    var imgWidth = vb[3] - vb[1];
    // image resize logic
    if(imgWidth > pageWidth){
        vb[3] = pageWidth;
        rect[0].visibleBounds = vb;
        rect[0].fit(FitOptions.PROPORTIONALLY);
        rect[0].fit(FitOptions.FRAME_TO_CONTENT);
    }

如何对溢出文本中的图像应用一些逻辑?如何调整溢出文本中的图像大小?

我们可以将下面的 word 文件导入到任何 InDesign 模板中

Sample word file

【问题讨论】:

    标签: javascript adobe-indesign


    【解决方案1】:

    您可以遍历所有图形并调整大图形的大小。

    var images = app.activeDocument.allGraphics;
    
    var max   = {};
        max.w = 100; // max width
        max.h = 100; // max height
    
    for (var i=0; i<images.length; i++) {
    
        var gb     = images[i].geometricBounds;
        var size   = {};
            size.w = -gb[1] + gb[3];
            size.h = -gb[0] + gb[2];
    
        if (size.w > max.w || size.h > max.h) {
            var scale = (size.w > size.h) ? max.w/size.w : max.h/size.h;
            images[i].horizontalScale *= scale;
            images[i].verticalScale   *= scale;
            images[i].parent.fit(FitOptions.FRAME_TO_CONTENT);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-23
      • 1970-01-01
      • 2017-08-06
      • 2014-08-09
      相关资源
      最近更新 更多