Copy link to clipboard
Copied
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?
And here a PDF about using transform() with a transformationMatrix:
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
Copy link to clipboard
Copied
Hey, guys!
No one has a solution?
Copy link to clipboard
Copied
Hellowwwooowww!
Is there anybody out there?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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…
Copy link to clipboard
Copied
I think you're getting into trouble using the top left anchor as your transformation point. Try using the center anchor.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@zeRafio – ok, this is not AppleScript, but ExtendScript (JavaScript):
http://jongware.mit.edu/idcs6js/pc_Rectangle.html#resize
Example before Script:
After Script:
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
Copy link to clipboard
Copied
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:
Uwe
Copy link to clipboard
Copied
Here another close up of both overlapping rectangles showing the shift:
Uwe
Copy link to clipboard
Copied
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.
Uwe
Copy link to clipboard
Copied
And here a PDF about using transform() with a transformationMatrix:
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
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now