Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I only want to shrink the image frame without affecting the cropped portion.

Guide ,
Sep 19, 2025 Sep 19, 2025

I only want to shrink the bottom frame without affecting the cropped section on the right.

 

sel.fit(FitOptions.FRAME_TO_CONTENT);
sel.fit(FitOptions.FILL_PROPORTIONALLY);

Neither seems to work. Is there a better solution?

006.png

 

 

TOPICS
How to , Scripting
132
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 19, 2025 Sep 19, 2025

It isn't that complicated. You don't need `getGraphics` function if you already have the graphic some other way. You can move the `intersection` logic inside the `intersectionOfGraphicFrame` function. The whole thing—minus the checking and getting—boils down to this one operation:

graphic.parent.geometricBounds =  [
    graphic.geometricBounds[0] > graphic.parent.geometricBounds[0] ? graphic.geometricBounds[0] : graphic.parent.geometricBounds[0],
    graphic.geometricBounds[1] > graphic.parent.g
...
Translate
Community Expert ,
Sep 19, 2025 Sep 19, 2025

Hi @dublove, like this ...

/**
 * @file Intersect Graphic Frame.js
 *
 * Example, setting the selected graphics' frames size to match the intersection of their bounds.
 *
 * @author m1b
 * @version 2025-09-20
 * @discussion https://community.adobe.com/t5/indesign-discussions/i-only-want-to-shrink-the-image-frame-without-affecting-the-cropped-portion/m-p/15512777
 */
function main() {

    var doc = app.activeDocument;
    var graphics = getGraphics(doc.selection);

    for (var i = 0; i < graphics.length; i++)
        intersectionOfGraphicFrame(graphics[i]);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Intersect Graphic Frames');

/**
 * Returns graphics derived from `items`.
 * @author m1b
 * @version 2025-08-20
 * @param {Array|PageItem} items - array or collection or page item.
 */
function getGraphics(items) {

    var graphics = [];

    if ('Array' === items.constructor.name) {

        for (var i = 0; i < items.length; i++)
            graphics = graphics.concat(getGraphics(items[i]));

    }

    else if (
        items.hasOwnProperty('allGraphics')
        && items.allGraphics.length > 0
    )
        graphics = graphics.concat(items.allGraphics);

    else if (
        items.hasOwnProperty('allPageItems')
        && items.allPageItems.length > 0
    )
        graphics = graphics.concat(getGraphics(items.allPageItems));

    else if ('Image' === items.constructor.name) {
        graphics.push(items);
    }

    return graphics;

};

/**
 * Sets the graphic's container's size to match the intersection of their bounds.
 * @author m1b
 * @version 2025-09-20
 * @param {PageItem} graphic - a page item contained in another page item.
 */
function intersectionOfGraphicFrame(graphic) {

    if (
        !graphic
        || !graphic.parent
        || !graphic.parent.geometricBounds
    )
        return;

    graphic.parent.geometricBounds = intersection(graphic.geometricBounds, graphic.parent.geometricBounds);

};

/**
 * Returns the intersecting bounds of b0 and b1.
 * @param {Array<Number>} b0 - a bounds array.
 * @param {Array<Number>} b1 - a bounds array.
 */
function intersection(b0, b1) {

    return [
        b0[0] > b1[0] ? b0[0] : b1[0],
        b0[1] > b1[1] ? b0[1] : b1[1],
        b0[2] < b1[2] ? b0[2] : b1[2],
        b0[3] < b1[3] ? b0[3] : b1[3],
    ];

};
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 19, 2025 Sep 19, 2025

Hi m1b.

Thank you very much.

 

I didn't expect it to be so complicated to implement.
I'm still experimenting, and it works best when combined with:

s.fit(FitOptions.FILL_PROPORTIONALLY);
s.fit(FitOptions.FRAME_TO_CONTENT);

If not handled properly, they will clash.
It might take some getting used to.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2025 Sep 19, 2025

It isn't that complicated. You don't need `getGraphics` function if you already have the graphic some other way. You can move the `intersection` logic inside the `intersectionOfGraphicFrame` function. The whole thing—minus the checking and getting—boils down to this one operation:

graphic.parent.geometricBounds =  [
    graphic.geometricBounds[0] > graphic.parent.geometricBounds[0] ? graphic.geometricBounds[0] : graphic.parent.geometricBounds[0],
    graphic.geometricBounds[1] > graphic.parent.geometricBounds[1] ? graphic.geometricBounds[1] : graphic.parent.geometricBounds[1],
    graphic.geometricBounds[2] < graphic.parent.geometricBounds[2] ? graphic.geometricBounds[2] : graphic.parent.geometricBounds[2],
    graphic.geometricBounds[3] < graphic.parent.geometricBounds[3] ? graphic.geometricBounds[3] : graphic.parent.geometricBounds[3],
];

 

The larger issue is you don't always do a very good job of giving us examples that cover all your needs. The code I wrote works perfectly on your example document. But now you are talking about the `fit` method—which has nothing to do with your example. I know it can be hard., but try to supply examples that cover all your cases.

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 19, 2025 Sep 19, 2025

This is easier to understand.
It must be quite useful.
I just can't use too many features right now, or it'll get cluttered.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2025 Sep 20, 2025

Okay, that's good. Using single-purpose functions—as many as you need—is normal programming. Just include them in an external file and forget about them. There is no clutter to your main script file.

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 20, 2025 Sep 20, 2025

I've taken many detours.
I'll revise all my old code when I have time.
For instance, I often conflate the current selection with the final target of an operation, interspersing various transformations in between.

From now on, I'll strictly separate them into two distinct categories:
'item' represents the current selection, while 'sel' denotes the final target of the operation. 'sel' must be an object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 20, 2025 Sep 20, 2025
LATEST

Hi @m1b 

Please take a look at another issue—the text box is suitable for text content.
Thanks.

 

https://community.adobe.com/t5/indesign-discussions/how-to-use-a-script-to-make-the-bottom-and-right...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines