Copy link to clipboard
Copied
Hi,
I am trying to run a script that resets image fitting. I am having issues with the cropping. I don't understand the hirarchy of the geormetricbounds vs cropping vs fitting of an image in a rectangle.
I want to be able to swap image within a rectangle in a clean predicatble way witout crop values of the original image in the rectangle. I want to reset the crop to be 0 on all 4 sides like i can in the interface. set the image rectangle to be fill proportionally, autofit and be able to set an align from. When I run my script I get back and image with a crop factor on it instead of crop being [0,0,0,0]
Here is a code snippet from what I have so far:
Copy link to clipboard
Copied
Does this get you closer to what you need?
function main() {
if (app.selection.length === 0) {
alert("Please select a valid image frame.");
return;
}
var targetObject = app.selection[0];
// Check if the target object supports frame fitting options and contains graphics.
if (typeof targetObject.frameFittingOptions === "undefined" || !targetObject.graphics || targetObject.graphics.length === 0) {
alert("Selected object is not a valid image container or does not contain an image!");
return;
}
var graphic = targetObject.graphics[0];
// Reset any transformations (scaling, rotation)
graphic.absoluteHorizontalScale = 100;
graphic.absoluteVerticalScale = 100;
graphic.rotationAngle = 0;
// Clear any previously set frame fitting options to remove cropping and adjustments.
targetObject.clearFrameFittingOptions();
// Reset the graphic's bounds to match the frame's bounds.
// This effectively removes any residual cropping.
graphic.geometricBounds = targetObject.geometricBounds;
// Temporarily disable autoFit to prevent interference.
targetObject.frameFittingOptions.autoFit = false;
// Apply the desired fitting method. Here we use Fill Proportionally.
targetObject.fit(FitOptions.FILL_PROPORTIONALLY);
// Optionally, re-enable autoFit if that's part of your workflow.
targetObject.frameFittingOptions.autoFit = true;
alert("Image fitting reset successfully on a " + targetObject.constructor.name + ".");
}
main();