Copy link to clipboard
Copied
I am resizing a book with on the left (even) pages an imageframe (with the jpg of the old format) that needs to be resized to (in mm)
x = -3
y = -3
width = 153 mm
hight = 236 mm
image scaled (both horizotal and vertical) to 110%
jpeg positioned in centre of the frame.
I cannot find a script that I can modify to these dimensions. as it is 500 + images I am very greatfull fo any help on getting a script that would do this trick.
Best, Joop
Hi @joop25628618fwiu, I wrote a similar script recently so it was easy to adapt to your request. Let me know if it works for you. I have commented the script so hopefully you can follow along what it is doing.
- Mark
/**
* Performs sizing, scaling and
* content-fitting on first rectangle
* on every left-hand page.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/script-request/m-p/13131713
*/
function main() {
app.scriptPreferences.measurementUnit ...
Copy link to clipboard
Copied
Hi @joop25628618fwiu, I wrote a similar script recently so it was easy to adapt to your request. Let me know if it works for you. I have commented the script so hopefully you can follow along what it is doing.
- Mark
/**
* Performs sizing, scaling and
* content-fitting on first rectangle
* on every left-hand page.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/script-request/m-p/13131713
*/
function main() {
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var mm = 2.83465,
// the adjustments:
settings = {
newFrameBounds: [-3 * mm, -3 * mm, 233 * mm, 150 * mm],
graphicScalePercent: 110,
}
if (app.documents.length == 0) {
alert('Please open a document and try again.');
return;
}
var doc = app.activeDocument,
spreads = doc.spreads,
counter = 0;
// check through all spreads
for (var i = 0; i < spreads.length; i++) {
// we only want spreads with 2 pages
if (spreads[i].pages.length == 2)
// if it has a rectangle
// and it has a graphic
if (
spreads[i].pages[0].rectangles[0].isValid
&& spreads[i].pages[0].rectangles[0].hasOwnProperty('graphics')
&& spreads[i].pages[0].rectangles[0].graphics.length > 0
&& spreads[i].pages[0].rectangles[0].graphics[0].isValid
) {
// perform the adjustments
adjustFrame(spreads[i].pages[0].rectangles[0], settings.newFrameBounds, settings.graphicScalePercent, true);
counter++;
}
}
// finished
alert('Adjusted ' + counter + ' graphics frames.');
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Adjust LHS graphic");
/**
* Sets a graphic frame's bounds
* and scales and centers graphic.
* @param {Rectangle} frame - an Indesign Rectangle.
* @param {Array} bounds - the new bounds [T, L, B, R].
* @param {Number} scale - the graphic scale percentage.
* @param {Boolean} absoluteScale - whether scalePercent is absolute or relative.
*/
function adjustFrame(frame, bounds, scale, absoluteScale) {
if (bounds != undefined)
frame.geometricBounds = bounds;
var graphic = frame.graphics[0];
if (scale != undefined)
if (absoluteScale) {
graphic.absoluteHorizontalScale = scale;
graphic.absoluteVerticalScale = scale;
}
else {
graphic.resize(
BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS,
AnchorPoint.BOTTOM_LEFT_ANCHOR,
ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,
[scale / 100, scale / 100]
);
}
graphic.fit(FitOptions.CENTER_CONTENT);
};
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi Joop, you're confusing me. Why would you convert it to applescript? Did you try running the script as is? See instructions. Save it as a plain text file with a ".js" extension, and put it in the Scripts Panel folder. A quick way to locate the Scripts Panel folder is to right-click or control-click a script in the Scripts panel, and choose Reveal In Finder.
Then open your document and run the script from the Scripts panel.
- Mark
Copy link to clipboard
Copied
Hi Mark,
Thanks again, it is working better on a small extracted indd of 30 pages. The 1500 pages doc gives this error I don't understand why only in the small doc this error is given:
I ment the final percentage of the image should be 110%, when I run the script twice, it is gonna be 121 etc percent. I have set most images by hand on 110% already so I set graphicScalePercent: 100 (works ok).
Copy link to clipboard
Copied
I found a corrupted image that coused the error.
thanks for your help !!
Copy link to clipboard
Copied
Yes the first script will scale graphic every time you run it. I have changed it now to set the scale of the graphic to an absolute value, eg. 110%. It means that every graphic found would have scale 110%.
- Mark
Copy link to clipboard
Copied
you saved my week!
keep up the scripting.
Best, Joop
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more