Copy link to clipboard
Copied
Hi,
I am working on a document with 500 images and all of them run beyond the text frame size. Hence, to fit them to the frame, I tried to use Transform->Scale and set the percentage value to less than 100% and the image got fit into the text frame. However, the problem is with a single selection. Selecting an image every time and setting the scale for 500 objects is a time consuming task. (Kindly note that all images are inline hence, I cannot use ScaleGraphics to resize them all at once).
I tried using Object style but it does not incorporate Scale option in its palette. I tried using Find/Change option but it does not take anything other than an Object style, hence bringing me back to square one. I urge all the InDesign experts to provide their thoughts on the following question related to the problem:
Is it possible to apply Scale option to all the images at once - a script or plugin or simple technique?
Any guidance in the right direction would be greatly appreciated. Hope to receive a positive response.
Regards,
Aman Mittal
amanm5143 wrote
2. I had set the Auto-sizing Option in the Text Frame Options to "Width and Height"
[...]
Though the script worked but it cropped the right side part of the image to fit to the width and bottom part to fit to the height. Basically, it trimmed the images to fit to the size of text frame.
Well, I actually meant Object style > Fitting options, not Text Frame Options > Auto-sizing.
This is why your images got cropped.
Now, thinking about it, maybe auto-fitting is not what you want...
So,
...Copy link to clipboard
Copied
Hi Uwe,
Thanks—I didn't notice there was a competing thread on the same topic. So by joining forces we should succeed 😉
Best,
Marc
Copy link to clipboard
Copied
Hi,
Firstly, a big thank you to both - vinny38​ and Laubender​ for dedicating their valuable time to the query. I am truly lucky to have been supported by you guys.
Laubender​: As per your suggestion, I did check out the mages in the word document and they appear to be normal (not cropped).
vinny38​: Though experts have shown a kind gesture of looping in and providing valuable inputs but you have been the torch bearer and main lead for this query. Your solution and zeal provided the necessary break-through, so I urge you to take it to the finish line, as well. Your indulgence and dedication towards the puzzle enticed others to take an interest. So, request you to not leave us hanging, now when you have almost solved the puzzle. Once it is done, the whole community will be grateful to you because this is one of the problems which has been faced by every user, atleast once.
I tried both versions of the script and, below are the notes:
Version 4:
Version 4 worked perfectly for few images.
Below image was out of bounds in terms of "width and not height". So, the script perfectly rescaled the image under text frame size.
However, for very large images, it followed the script's approach of rescaling by a factor of 5%. The small cross was a large image which was out of bound on both ends - width as well as height. Though this is a minor issue, as one can change the scale factor to make the necessary adjustment.
Major point of concern in Version 4 was that the script re-scaled the in-bound images as well (those which were well under the text frame size) leading to loss of pixel density in case of small images and major underscaling (5%), in case of normal sized images.
Your script definitely solved the problem of overflow as the whole text flowed perfectly. This is major breakthrough. I repeat, a major one. This is gonna help in creating a simpler workflow for many users. Big Thank You!!!1
I guess, you tried to tackle the issue with version 5 which may leave in-bound images, unattended.
Version 5:
Whenever I try to run the script, it gives the following error:
I checked for Anchor Positioning as well and it was fine. So, I am not able to figure out the cause of the error.
Regards,
Aman
Copy link to clipboard
Copied
Hi Aman
Hard to tell what's returning the error... (Working here...)
Did you copy correctly the entire javascript?
Or maybe the order of the instructions were not right after all...
I doubt it will fix the issue, but please try this version 6, slightly modified:
//FitAnchorToColumn v6
//by Vinny
if (parseFloat(app.version) < 6)
main();
else
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn");
function main() {
if (app.documents.length > 0) {
var
myDoc = app.activeDocument,
myFound;
app.findObjectPreferences = null;
app.findObjectPreferences.anchoredPosition = AnchorPosition.INLINE_POSITION;
app.findChangeObjectOptions.objectType = ObjectTypes.GRAPHIC_FRAMES_TYPE;
myFound = myDoc.findObject();
// change everything to custom position
for (i = 0; i < myFound.length; i++) {
myFound.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
}
//then check and transform
for (i = 0; i < myFound.length; i++) {
var
columnWidth = myFound.parent.parentTextFrames[0].textFramePreferences.textColumnFixedWidth,
columnHeight = myFound.parent.parentTextFrames[0].geometricBounds[2] - myFound.parent.parentTextFrames[0].geometricBounds[0],
myObjectWidth = myFound.geometricBounds[3] - myFound.geometricBounds[1],
myObjectHeight = myFound.geometricBounds[2] - myFound.geometricBounds[0],
myScaleFactorH = columnWidth / myObjectWidth,
myScaleFactorV = columnHeight / myObjectHeight,
myScaleMatrixH = app.transformationMatrices.add({
horizontalScaleFactor: myScaleFactorH,
verticalScaleFactor: myScaleFactorH
}),
myScaleMatrixV = app.transformationMatrices.add({
horizontalScaleFactor: myScaleFactorV,
verticalScaleFactor: myScaleFactorV
});
if (myObjectWidth > columnWidth && myObjectHeight <= columnHeight) {
myFound.transform(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.TOP_LEFT_ANCHOR,
myScaleMatrixH);
} else if (myObjectHeight > columnHeight) {
myFound.transform(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.TOP_LEFT_ANCHOR,
myScaleMatrixV);
} else {
// nothing happens;
}
}
// change back to inline position
for (i = 0; i < myFound.length; i++) {
myFound.anchoredObjectSettings.anchoredPosition = AnchorPosition.INLINE_POSITION;
}
} else {
alert("Open a document");
}
}
Now, if you still have a javascript error, which is most likely to be the case, please remove line 3, 5 and 6 so that :
if (parseFloat(app.version) < 6)
main();
else
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn");
Turns to
main();
Run the script again and please report back the new javascript error, which will hopefully tell us more...
Please note that I won't be available till Thursday to try to fix the issue, but probably others will help...
Regards
Vinny
Copy link to clipboard
Copied
Hey vinny38​,
I perfectly understand you must be busy with other things. I am already grateful to you for taking out the time from your busy schedule for such an activity. So, we shall continue it after Thursday, then.
I tried version 6 and as you rightly predicted, the script gave the same error so I tweaked the script a explained. After running the modified version, text flowed without any overset as the script had custom lined the images however, it did not scale the images to text frame size and gave the following error:
For your ease, I am attaching a sample INDD document with certain caveats:
https://drive.google.com/file/d/19SrwcPWRUqLMrdgHLOSpdCpNRfw11bwA/view?usp=sharing
1. I have removed the image content however, the image frames are intact and untouched which shall serve the same purpose.
2. All the images have Anchored Object Positioning: Above or Inline, as the original word document have inline images
3. You will find that the text overflows due to the varying size of images which run beyond the text frame size.
4. If you apply Anchored Object Positioning: Custom through all Find/Change to all the Objects then, the file will start to flow and you will see images frames of varying sizes.
Hope, this will help in achieving the desired results.
Regards,
Aman
Copy link to clipboard
Copied
Hi Aman
Let's continue this discussion here: Scale all images at once in InDesign
Copy link to clipboard
Copied
@Laubender,
Vinny seems to be helping, if the OP kept it to one single thread instead of making double threads all info would be easier to find and all together.