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

[AS/CC]Resizing a box and its contained image

Contributor ,
Feb 02, 2014 Feb 02, 2014

Is there a method ro resize by percentage a box and the image inside?

My code for this is the following:

(first line for the box, second for the image)

  resize selection in inner coordinates from top left anchor by multiplying current dimensions by values {0.75, 0.75} with resize individually and considering ruler units

  resize image 1 of selection in parent coordinates from top left anchor by multiplying current dimensions by values {0.75, 0.75} with resize individually and considering ruler units

But unfortunately, if the image is skewed, the result is not what we can expect: the image is resized, but misplaced.

Any suggestion?

TOPICS
Scripting
3.3K
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 , Feb 08, 2014 Feb 08, 2014

And here a PDF about using transform() with a transformationMatrix:

 

indesigncs3_transform_tutorial_javascript.pdf

 

http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products /indesign/pdfs/indesigncs3_transform_tutorial_javascript.pdf

 

Uwe

 

PS: Unfortunately the link above is not working anymore.

 

Instead see into:

Coordinate Spaces & Transformations in InDesign [UPDATE]
Marc Autert, October 14, 2021 | Tips | en
https://indiscripts.com/post/2018/06/coordinate-spaces-and-transformations-5

Translate
Contributor ,
Feb 05, 2014 Feb 05, 2014

Hey, guys!

No one has a solution?

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
Contributor ,
Feb 06, 2014 Feb 06, 2014

Hellowwwooowww!

Is there anybody out there?

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 ,
Feb 06, 2014 Feb 06, 2014

If AppleScript behaves the same as JavaScript in this regard, then the answer is 'no', there is no single command for that. I wouldn't resize the image after resizing the rectangle, by the way, but fit the image to the rectangle, which would ensure a good fit. In JS:

myFrame.resize // as you have it

myFrame.fit (FitOptions.contentToFrame)

Peter

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
Contributor ,
Feb 06, 2014 Feb 06, 2014

Peter,

Unfortunately, your suggestion is invalid for my script:

I want to modify cropped, scaled and even rotated images.

So I have to write tons of code to re-place those images.

I'm dreaming of a <resize myFrame with content> command!

Why can't we do by scripting things we can do manually? (this is for Adobe developpers, of course (and I know they are rarely visiting this board…))

Thank you anyway…

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
Engaged ,
Feb 06, 2014 Feb 06, 2014

I think you're getting into trouble using the top left anchor as your transformation point. Try using the center anchor.

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
Contributor ,
Feb 08, 2014 Feb 08, 2014

Hello Mary,

Thank you for participating, but…

Did you try what you suggested?

The anchor point does not help.

Anyway, I have written some extra code to re-calculate the position of the image relatively to its container frame.

My aim was to simplify the code…

I really don't understand how Adobe developpers are thinking (I'm not speaking of you):

Chief developper:

"Hey, guys wouldn't be great if we implement a resize command?"

The crawler:

- "Yes and it could resize pages, groups, frames, images, etc…"

The new guy:

- "Even an image and its frame!"

… (silence)

Chief  developper:

- "Naaaaaaaah, this is stupid, who wants that? No one needs such a behavior, believe me."

In fact, I'm scripting Indesign since version 2.

And I'm waiting for such a stupid command since that.

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 ,
Feb 08, 2014 Feb 08, 2014

@zeRafio – ok, this is not AppleScript, but ExtendScript (JavaScript):

http://jongware.mit.edu/idcs6js/pc_Rectangle.html#resize

Example before Script:

BeforeScript_Rectangle.png

BeforeScript_Image.png

After Script:

AfterScript_Rectangle.pngAfterScript_Image.png

ExtendScript (JavaScript) working with the selected rectangle, that holds an image:

//Setting preferences (not necessary, but could be wise):

app.transformPreferences.whenScaling = WhenScalingOptions.ADJUST_SCALING_PERCENTAGE;

//Working on the selected rectangle:

app.selection[0].resize(

    CoordinateSpaces.INNER_COORDINATES,

    AnchorPoint.CENTER_ANCHOR,

    ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,

    [0.5,0.5],

    false,

    undefined

    );

//Working on the image inside the rectangle:

app.selection[0].pageItems[0].getElements()[0].resize(

    CoordinateSpaces.INNER_COORDINATES,

    AnchorPoint.CENTER_ANCHOR,

    ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,

    [0.5,0.5],

    false,

    undefined

    );

Uwe

//EDIT: oops. I see the image shifting…

Message was edited by: Laubender

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 ,
Feb 08, 2014 Feb 08, 2014

Even with using PASTEBOARD_COORDINATES a small shift will occur:

app.transformPreferences.whenScaling = WhenScalingOptions.ADJUST_SCALING_PERCENTAGE;

var mySel = app.selection[0];

mySel.resize(

    CoordinateSpaces.PASTEBOARD_COORDINATES,

    AnchorPoint.CENTER_ANCHOR,

    ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,

    [0.5,0.5],

    false,

    undefined

    );

   

mySel.pageItems[0].getElements()[0].resize(

    CoordinateSpaces.PASTEBOARD_COORDINATES,

    AnchorPoint.CENTER_ANCHOR,

    ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,

    [0.5,0.5],

    false,

    undefined

    );

Here a screenshot where I used two methods to scale:

The blue, overprinting rectangle resized by the above script overlapping the yellow, overprinting rectangle using the percentage method in the UI. The red arrow points at the amount of shift:

AmountOfShift_USING_PasteBoardCoordinates.png

Uwe

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 ,
Feb 08, 2014 Feb 08, 2014

Here another close up of both overlapping rectangles showing the shift:

CloseUpOfShift.png

Uwe

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 ,
Feb 08, 2014 Feb 08, 2014

Well. There is another method:

use a transformation matrix.

 

/*
Scales the selected object with the image to 50%:
scaleMatrix( .5 , .5 )
through method transform() on the selection.
*/

var mySel = app.selection[0];

var myTransformationMatrix = 
app.transformationMatrices.add
(
{
horizontalScaleFactor:1, 
verticalScaleFactor:1
}
);

myTransformationMatrix = 
myTransformationMatrix.scaleMatrix(.5, .5);

mySel.transform
(
CoordinateSpaces.pasteboardCoordinates, 
AnchorPoint.centerAnchor, 
myTransformationMatrix
);

 

And that seems to be the solution.

Rectangle plus image scaled in one go.

 

Here the proof with two overprinting rectangles overlapping perfectly. One scaled with the script above, one scaled with the UI. No shift visible.

 

ScaledByTransformationMatrix.png

 

Uwe

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 ,
Feb 08, 2014 Feb 08, 2014

And here a PDF about using transform() with a transformationMatrix:

 

indesigncs3_transform_tutorial_javascript.pdf

 

http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products /indesign/pdfs/indesigncs3_tr...

 

Uwe

 

PS: Unfortunately the link above is not working anymore.

 

Instead see into:

Coordinate Spaces & Transformations in InDesign [UPDATE]
Marc Autert, October 14, 2021 | Tips | en
https://indiscripts.com/post/2018/06/coordinate-spaces-and-transformations-5

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
Contributor ,
Feb 13, 2014 Feb 13, 2014
LATEST

That's it!

Uwe, you're the man!

How could I miss this method?

The name is clear enough!

BTW, my apologies to the Adobe developpers.

This is my code in Appplescript

          set scaleMatrix to make transformation matrix with properties {horizontal scale factor:0.5, vertical scale factor:0.5}

  transform selection in pasteboard coordinates from top left anchor with matrix scaleMatrix

And (of course) it works with multiple selection and groups with no additional code.

The link for the same document as yours but for AS: https://wwwimages2.adobe.com/content/dam/Adobe/en/products/indesign/pdfs/indesigncs3_transform_tutor...

With all my thanks.

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