Skip to main content
Inspiring
June 14, 2018
Answered

Scale all images at once in InDesign

  • June 14, 2018
  • 2 replies
  • 28095 views

Hi,

I am working on a document with 500 images and all of them run beyond the text frame size. Hence, to fit them to the frame, I tried to use Transform->Scale and set the percentage value to less than 100% and the image got fit into the text frame. However, the problem is with a single selection. Selecting an image every time and setting the scale for 500 objects is a time consuming task. (Kindly note that all images are inline hence, I cannot use ScaleGraphics to resize them all at once).

I tried using Object style but it does not incorporate Scale option in its palette. I tried using Find/Change option but it does not take anything other than an Object style, hence bringing me back to square one. I urge all the InDesign experts to provide their thoughts on the following question related to the problem:

Is it possible to apply Scale option to all the images at once - a script or plugin or simple technique?

Any guidance in the right direction would be greatly appreciated. Hope to receive a positive response.

Regards,

Aman Mittal

This topic has been closed for replies.
Correct answer vinny38

amanm5143  wrote

2. I had set the Auto-sizing Option in the Text Frame Options to "Width and Height"

[...]

Though the script worked but it cropped the right side part of the image to fit to the width and bottom part to fit to the height. Basically, it trimmed the images to fit to the size of text frame.

Well, I actually meant Object style > Fitting options, not Text Frame Options > Auto-sizing.

This is why your images got cropped.

Now, thinking about it, maybe auto-fitting is not what you want...

So, lets think differently. Instead of resizing the frame, let's rescale it.

Give this version 2 script a try and tell me if it works for you.

Besides, I modified it because not everyone works in millimeters... It now should work whatever measurement units are in use.

I also "wrapped" it, so you can CTRL-Z it now...

//FitAnchorToColumn v2

//Transform anchored objects in order to rescale them to make them fit column width, keeping proportions.

//by Vinny

if (parseFloat(app.version) < 6)

    main();

else

    app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn");

function main() {

    if (app.documents.length > 0) {

        var

        myDoc = app.activeDocument,

        docUnits = myDoc.viewPreferences.horizontalMeasurementUnits;

        app.findGrepPreferences = app.changeGrepPreferences = null;

        app.findGrepPreferences.findWhat = "~a"

        var myFound = myDoc.findGrep();

        for (i = 0; i < myFound.length; i++) {

            if (typeof myFound.parentTextFrames[0] != "undefined") {

                var columnWidth = myFound.parentTextFrames[0].textFramePreferences.textColumnFixedWidth,

                myObjectWidth = myFound.pageItems[0].geometricBounds[3]-myFound.pageItems[0].geometricBounds[1],

                myScaleFactor = columnWidth/myObjectWidth,

                myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:myScaleFactor,verticalScaleFactor:myScaleFactor});

                

                myFound.pageItems[0].transform(

                    CoordinateSpaces.INNER_COORDINATES,

                    AnchorPoint.TOP_LEFT_ANCHOR,

                    myScaleMatrix

                );

            }

        }

        app.findGrepPreferences = app.changeGrepPreferences = null;

    } else {

        alert("Open a document");

    }

}

amanm5143  wrote

Additionally, it didn't run on every text frame; I had to select each text frame and run the script again to make the desired changes.

Hmmmm... that's strange. I don't know what to tell you. It should affect the whole document...

Let's see if version 2 magically solves it ^^

2 replies

vinny38
Legend
June 14, 2018

Hi.

Interesting question.

Could you give this script a try and report back?

//FitAnchorToColumn v1

//Fit anchored objects to column width keeping proportions

//by Vinny

if (app.documents.length > 0) {

    var myDoc = app.activeDocument;

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.findWhat = "~a"

    var myFound = myDoc.findGrep();

    for (i = 0; i < myFound.length; i++) {

        if (typeof myFound.parentTextFrames[0] != "undefined") {

            var columnWidth = myFound.parentTextFrames[0].textFramePreferences.textColumnFixedWidth;

            myFound.pageItems[0].resize(

                CoordinateSpaces.INNER_COORDINATES,

                AnchorPoint.TOP_LEFT_ANCHOR,

                ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [UnitValue(columnWidth + 'mm').as('pt'), ResizeConstraints.KEEP_CURRENT_PROPORTIONS]

            );

        }

    }

} else {

    alert("Open a document");

}

Script detect column width for a anchored object, then resize it.

Text will then reflow, so make sure you have consistent number of columns and column width (using primary text frames?), otherwise reflow could mess the whole thing.

Edit:

Oh I forgot to say that script only resizes the anchored object itself, not the imported graphic.

In my example, I used an Object style for my pics, with auto-resize ON

amanm5143Author
Inspiring
June 14, 2018

Hi Vinny,

Thank you for taking out the time to find a solution and work upon the same. I tried your solution following these conditions:

1. All the images were anchored

2. I had set the Auto-sizing Option in the Text Frame Options to "Width and Height"

3. Anchor Position was not changed.

4. Column width and numbers were of fixed number - 1

Though the script worked but it cropped the right side part of the image to fit to the width and bottom part to fit to the height. Basically, it trimmed the images to fit to the size of text frame. Additionally, it didn't run on every text frame; I had to select each text frame and run the script again to make the desired changes.

I think my problem would get resolved if I am able to use the Transform tool to change the percentage value from 100% for all images, BUT, at a single go.

I appreciate your hard work and am grateful to you for trying things out. I hope The report contained all the necessary info. Looking forward to your reply.

Regards,

Aman Mittal

vinny38
Legend
June 15, 2018

Hey Vinny,

Regarding the latest, I have got an update. The script does adjust the height as well, it is just that it does not rescales the height for the very large images though it does the same for column width. So, is there a way to tweak the script to make InDesign rescale the height upto the height of the text frame?

Regards,

Aman Mittal    


If I understand you correctly, you have cases where your anchored image is very high and overflows after applying the script.

Just like this example:

In which case, you can try version 3 of the script which will resize height while trimming top and bottom of the image:

//FitAnchorToColumn v3

//Transform anchored objects in order to rescale them to make them fit column width, keeping proportions.

//by Vinny

if (parseFloat(app.version) < 6)

    main();

else

    app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn");

function main() {

    if (app.documents.length > 0) {

        var

            myDoc = app.activeDocument,

            docUnits = myDoc.viewPreferences.horizontalMeasurementUnits,

            myFound;

        app.findGrepPreferences = app.changeGrepPreferences = null;

        app.findGrepPreferences.findWhat = "~a";

        myFound = myDoc.findGrep();

        for (i = 0; i < myFound.length; i++) {

            if (typeof myFound.parentTextFrames[0] != "undefined") {

                var

                    columnWidth = myFound.parentTextFrames[0].textFramePreferences.textColumnFixedWidth,

                    columnHeight = myFound.parentTextFrames[0].geometricBounds[2] - myFound.parentTextFrames[0].geometricBounds[0],

                    myObjectWidth = myFound.pageItems[0].geometricBounds[3] - myFound.pageItems[0].geometricBounds[1],

                    myObjectHeight = myFound.pageItems[0].geometricBounds[2] - myFound.pageItems[0].geometricBounds[0],

                    myScaleFactor = columnWidth / myObjectWidth,

                    myScaleMatrix = app.transformationMatrices.add({

                        horizontalScaleFactor: myScaleFactor,

                        verticalScaleFactor: myScaleFactor

                    })

                if (myObjectHeight * myScaleFactor == columnHeight) {

                    return null;

                } else if (myObjectHeight * myScaleFactor < columnHeight) {

                    myFound.pageItems[0].transform(

                        CoordinateSpaces.INNER_COORDINATES,

                        AnchorPoint.TOP_LEFT_ANCHOR,

                        myScaleMatrix);

                } else {

                    myFound.pageItems[0].transform(

                        CoordinateSpaces.INNER_COORDINATES,

                        AnchorPoint.TOP_LEFT_ANCHOR,

                        myScaleMatrix

                    );

                    myFound.pageItems[0].resize(

                        CoordinateSpaces.INNER_COORDINATES,

                        AnchorPoint.CENTER_ANCHOR,

                        ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [ResizeConstraints.KEEP_CURRENT_VALUE,

                            UnitValue(columnHeight + String(docUnits)).as('pt')

                        ]

                    );

                }

            }

        }

        app.findGrepPreferences = app.changeGrepPreferences = null;

    } else {

        alert("Open a document");

    }

}

Now, I won't have much time today to work on that script, but feel free to post it to the InDesign Scripting forum if you have further requirements.

Scripting experts will be happy to help, and very possibly will come up with a much better and efficient script for you.

About the anchored object options, as Chad suggested, you should work with an object style.

Thanks for your kind comments, it was a very interesting question and puzzle, and I thank you for helping me improving my scripting skills ^^

Colin Flashman
Community Expert
Community Expert
June 14, 2018

Have you tried this script from in-tools?

Scale Graphics Script | in-tools.com

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
amanm5143Author
Inspiring
June 14, 2018

Hi Colin,

Thank you for taking out the time and replying to the discussion. As mentioned earlier, I had tried ScaleGraphics script. However, the script does not work for inline images (anchored images); it only works on unachored ones.

Regards,

Aman Mittal