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

How to use change setting in CONTENT_TO_FRAME

Community Beginner ,
May 24, 2024 May 24, 2024

Copy link to clipboard

Copied

35124368fx7y_0-1716544417829.png

Hello. Please help me program what you see in the screenshot. I need to change exactly the "Right" parameter and precisely using "Fit content to frame" .  I can't figure out how to change a specific individual parameter. Since such a setting exists, it means there is a way to change the “Right”.
I use AdobeInDesign 2023.

Here is my weird code:

// Запитати у користувача нове значення масштабу по осі X
var newXScale = prompt("Enter new X Scale Percentage:", "100");

// Перевірити, чи є значення числом і більше 0
if (!isNaN(newXScale) && newXScale > 0) {
    // Отримати вибраний об'єкт
    var selectedObject = app.selection[0];

    // Перевірити, чи обраний об'єкт існує
    if (selectedObject != null) {
        // Зберегти поточні розміри об'єкта
        var oldBounds = selectedObject.geometricBounds;
        var left = oldBounds[1];
        var right = oldBounds[3];
        var top = oldBounds[0];
        var bottom = oldBounds[2];
        var width = right - left;
        var height = bottom - top;

        /*/ Розрахувати нову ширину
        var newWidth = width * (newXScale / 100);

        // Застосувати новий масштаб по осі X, залишаючи правий край на місці
        selectedObject.resize(
            CoordinateSpaces.INNER_COORDINATES,
            AnchorPoint.RIGHT_CENTER_ANCHOR,
            ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
            [parseFloat(newXScale), 100]  // Масштабуємо лише по осі X
        );*/

        // Коригування рамки (frame) для відображення всього зображення
		selectedObject.fit(FitOptions.CONTENT_TO_FRAME);
		
		
		
		
		//selectedObject.horizontalScale(30);
		/*selectedObject.geometricBounds = [
                selectedObject.geometricBounds[0], 
                selectedObject.geometricBounds[1], 
                selectedObject.geometricBounds[2], 
                selectedObject.geometricBounds[3] -3
            ];*/
		//selectedObject.fit(FitOptions.FRAME_TO_CONTENT);

        alert("X Scale Percentage changed to " + newXScale + "% and adjusted from right to left.");
    } else {
        alert("Please select an object.");
    }
} else {
    alert("Please enter a valid number greater than 0.");
}

 

TOPICS
Bug , How to , InCopy workflow , Scripting

Views

279

Translate

Translate

Report

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 , May 26, 2024 May 26, 2024

Your Rectangle has allGraphics property - collection of all graphic objects - which you can use to acccess your Image:

 

var myImg = myRect.allGraphics[0];
myImg.geometricBounds = [10,10,10,50];

 

This Image has geometricBounds property - like any other graphic object - an array [top,left,bottom,right] - if you set some "wrong" values - you'll deform this image - your rectangle will remain intact.

 

In the example above - if your image is a square - [10,10,10,50] will get it stretched horizontal

...

Votes

Translate

Translate
Community Expert ,
May 24, 2024 May 24, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 Beginner ,
May 25, 2024 May 25, 2024

Copy link to clipboard

Copied

Hello, can you tell me which of these I should use?

Votes

Translate

Translate

Report

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 ,
May 25, 2024 May 25, 2024

Copy link to clipboard

Copied

rightCrop

 

Votes

Translate

Translate

Report

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 Beginner ,
May 25, 2024 May 25, 2024

Copy link to clipboard

Copied

I don't know why, but it doesn't work. Instead of narrowing the image, it just resizes it by X. Am I using it correctly?

selectedObject.frameFittingOptions.rightCrop = -3;


I need to achieve the "Narrow Image" effect in X, as if I held down CTRL and started cropping. This is the effect I need, please help me to code it, because I don't understand something

35124368fx7y_0-1716662865741.png

 

Votes

Translate

Translate

Report

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 ,
May 25, 2024 May 25, 2024

Copy link to clipboard

Copied

If you know the end size - you should rather use geometricBounds - [top, left, bottom, right] - and THEN set fit options.

 

I don't think you need image to be distorted? 

 

If you do - then image has its own geometricBounds property. 

 

Please search forum - or Google - for examples how to use geometricBounds. 

 

Votes

Translate

Translate

Report

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 Beginner ,
May 26, 2024 May 26, 2024

Copy link to clipboard

Copied

Yes, but geometricBounds just crops my image, and then any existing method just pushes it forward. But I need to narrow/deform the images. In general, this is part of one huge algorithm. First I name the image 296x210 mm, then I make a copy of it. I cut each copy in half (one for the right side, one for the left). Then I move the left one along the X 3mm to the left, and the right one 3mm to the right. After this, I return the piece of image to the center by 3mm. And the last step is to make a narrowing (scale, proportional scaling) by slightly tightening the ends on both sides. It is this step that I cannot program, since all the fittings known to me simply narrow the overall original picture, and not the cropped version. All I found was the setting, a screenshot of which I showed in the post itself. If you do it manually, you need to hold down control and drag the picture frame to the left for the right side and to the right for the left. Here is the whole algorithm in pictures:
1) Original image (cat for example)

35124368fx7y_0-1716730104985.png

2) I make copies and Paste in Place
35124368fx7y_1-1716730180812.png

3) I crop the left copy to the left (simply by dragging it over the edge of the frame). I crop the right copy to the right side. I get two pictures that still make up one

35124368fx7y_2-1716730201325.png

4) I drag the left copy along X by -3, the right copy by 3 mm (I get a small hole in the center between them)

35124368fx7y_3-1716730219830.png

5) Now I repeat the third point, only now I don’t crop the photo, but rather add pieces to it (to cover the center)

35124368fx7y_4-1716730233420.png

6) What I can't program. In order not to lose pieces of the image behind the frame, I hold down control and drag the frame (left image: the left side of the frame is pulled to the right side, right image: the right side of the frame is pulled to the left). What you see in the screenshot below is just too much, but so you understand what I’m talking about

35124368fx7y_5-1716730254228.png

So I cannot program exactly this effect to deform the picture, BUT ONLY FROM ONE ANGLE, because when using the fitting we will get:

35124368fx7y_6-1716730351798.png

That is, the entire picture is inserted into the frame and distorted, and not its cropped piece.

Don’t pay attention to this strange algorithm, I work in a book publishing house and this is how we work with images of books if it fits on two pages and we want to glue them together correctly. Usually we do this manually, but I want to automate this process. And yes, sorry for the mistakes in the text, I use Google translator)

Votes

Translate

Translate

Report

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 ,
May 26, 2024 May 26, 2024

Copy link to clipboard

Copied

LATEST

Your Rectangle has allGraphics property - collection of all graphic objects - which you can use to acccess your Image:

 

var myImg = myRect.allGraphics[0];
myImg.geometricBounds = [10,10,10,50];

 

This Image has geometricBounds property - like any other graphic object - an array [top,left,bottom,right] - if you set some "wrong" values - you'll deform this image - your rectangle will remain intact.

 

In the example above - if your image is a square - [10,10,10,50] will get it stretched horizontally 5x times.

 

Of course, you CAN'T use fit options afterwards - but you can use fit options as a first step - to automatically resize image for best fit inside the rectangle - after you set the size of the rectangle, to fit the image - then you can distort your image using geometricBounds.

 

 

Rectangle is a container for your image - it will crop visible part of the image if image is bigger than the rectangle / container.

 

 

Your 3rd manual step - narrowing Rectangle - you can do it in script by modifying geometricBounds of the Rectangle - Image will remain intact - will be cropped:

 

var myGB = myRect.geometricBounds;
myRect.geometricBounds = [myGB[0], myGB[1], myGB[2], myGB[3] - (myGB[3] - myGB[1]) / 2];

 

(myGB[3]-myGB[1])/2 is half of the width of your Rectangle - that you need to substract from the right side - myGB[3]. Of course you can substract any other value.

 

Or you can add it to the left side:

 

myRect.geometricBounds = [myGB[0], myGB[1], myGB[2], myGB[1] + (myGB[3] - myGB[1]) / 2];

 

If you know the width in advance - both lines will do the same - make it "50" wide(*) - depends on your Measuremment Units:

 

myRect.geometricBounds = [myGB[0], myGB[1], myGB[2], myGB[3] - 50];

myRect.geometricBounds = [myGB[0], myGB[1], myGB[2], myGB[1] + 50];

 

(*) - not exactly - 1st will narrow it by "50" - 2nd will make it exactly "50" wide.

The earlier code, where I calculate width and divide by 2 - will always work the same no matter if you substract from the right or add to the left.

 

Votes

Translate

Translate

Report

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