Skip to main content
Inspiring
June 14, 2018
Answered

Scale all images at once in InDesign

  • June 14, 2018
  • 2 replies
  • 28204 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 18, 2018

Hey Vinny,

Thank you for taking out the time again from your busy schedule. You are absolutely right. Version 3 rescales anchored object H & W proportionally, up to column width. However, it "resizes height by trimming the top and bottom part" which led to loss of image content for me. I was trying to achieve to what you did to column width with column height as well. A solution which could rescale the H & W proportionally up to column width and height, just like a Transform Tool while not trimming an part of the image.

I will try to as elaborate as I can be:

Text Frame size: 6.14 in x9.21 in

When I try to flow the file through “Place”, it shows like this (here the Anchored Object Positioning, by default is: InLine)

Then I change the Anchored Object Positioning to Custom for all graphic frames and the file starts to flow:

As you can see, few of the images are well within the frame size (5 in x 7.7 in) while few of them are too large to be accommodated to the text frame size. So, I follow the approach of Transform Tool and change the percentage value to rescale (not trim) them to fit to the text frame size (5in x 7.7in).

As I have to deal with 500+ images, using Transform Tool for each one of them becomes a humongous task. Therefore, I was looking for a solution which could "search and rescale (both width and height) the out of bound images in the entire document at a single go within the text frame size" without:

  • Trimming any part of the image as it leads to loss of image content
  • Changing the size of already in-bound images (the solution shall leave all those images unattended and unscaled which are already under the text frame size)

I hope I was able to clearly make you understand the problem and required solution. Thank you for giving this your due consideration.

Regards,

Aman Mittal


Hi Aman

I wish I could help further, but I really don't understand your workflow...

You are talking about custom positioning, but where is your anchored marker positioned?

On a single line? At the beginning of a paragraph?

Do you want a custom position in order to have this kind of layout? (calculating from the position of the anchor marker up to column bottom):

Or is it supposed to fit height like this (with no trimming, meaning extra white space around the picture):

Before thinking of scripting scenario, you should really think about pros and cons of either inline or custom positioning.

E.g: What about this kind of situations (custom positioning):

Custom positioning can be very tricky...

Your screenshots are very hard to understand, maybe you could post screenshots (bigger size) showing exactly what you want to achieve, and not what you currently get...

Vinny

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