Copy link to clipboard
Copied
Hi all,
I know there are plenty of 'resize image/frame' scripts, but I can't find something that quite works for my scenario...
I am copying a frame (with an image which is cropped by the frame) from one indesign file to another. I then want to run a script to scale the frame and its image to a specific pixel width whilst constraining the proportions and position of the image. The frame should also be centred.
This is simple to do manually by checking both Constrain Proportions and Frame-Fitting to Auto-Fit then typing the new pixel dimension as the width with the reference point.
The way that indesign positions things with geometric bounds array seems to make it much more complicated to do via script. Also, an object style won't work as indesign has a ridiculous pixel limit of 1440px.
Does anyone have a solution for this?
Thanks!!
Hi @Phildson , Select the image’s frame and try this—note that the selected frame or its image have to have their rotation set to 0, 90, or 180 in order to set the width this way:
app.scriptPreferences.measurementUnit = MeasurementUnits.PIXELS;
var n = 1440
var sel = app.activeDocument.selection[0];
if (!sel.hasOwnProperty("images")) {
alert("Please select a frame containing an image")
} else {
var img = sel.images[0];
var ib = img.geometricBounds;
var iw = ib[3]-ib[1];
var i
Copy link to clipboard
Copied
Scripting aside, did you know that you can resize frames + picture content to specific sizes by using the Control panel? Not the W and H fields. But the Scale X percentage and the Scale Y percentage. Nevermind the %. You just need to type in explicit measurements in px, pt, p, mm, cm, in. Usually the Constrain Proportions chainlink icon is already ticked on (which is what you want).
Copy link to clipboard
Copied
Cheers, Mike!
Yeah, there are quite a few ways of doing it manually. I can even scale (as you say) an item on one page and then use transform again to repeat on other pages. Problem is - that still works to the percentage of the previous transform even if you type in a pixel dimension manually, so any items that have a different initial size won't scale to the pixel width I want.
A script to set the input (in pixels) for the scale operation would be ideal, but I'm not sure if it's that simple....
Copy link to clipboard
Copied
I never knew that InDesign Object styles > Size and Position limit frame width sizes to 20 inches; ie 120 picas; ie 1440 points; ie ... 1440 pixels!
Seems arbitrarily low.
Copy link to clipboard
Copied
Yes! It's crazy. I only found out myself yesterday when I found a post from 2013 flagging it and asking Adobe to fix it. 2024 and we're still waiting!
Copy link to clipboard
Copied
Hi @Phildson , Select the image’s frame and try this—note that the selected frame or its image have to have their rotation set to 0, 90, or 180 in order to set the width this way:
app.scriptPreferences.measurementUnit = MeasurementUnits.PIXELS;
var n = 1440
var sel = app.activeDocument.selection[0];
if (!sel.hasOwnProperty("images")) {
alert("Please select a frame containing an image")
} else {
var img = sel.images[0];
var ib = img.geometricBounds;
var iw = ib[3]-ib[1];
var ih = ib[2]-ib[0];
var s;
if (iw >= ih) {
s = n * (iw/ih);
img.geometricBounds = [0,0,n,s]
sel.geometricBounds = [0,0,n,n]
} else {
s = n * (ih/iw)
img.geometricBounds = [0,0,s,n]
sel.geometricBounds = [0,0,n,n]
}
sel.fit(FitOptions.CENTER_CONTENT);
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
}
Before:
Copy link to clipboard
Copied
Also, I assume the reason for working in Pixels is you plan to export the page to an image format—you are not going to be printing the page at 20"x20" (1440px x 1440px). If that’s the case you could work in inches and set a resolution on Export that would give you 1440x1440. The image could be set to 4.8" x 4.8" with the Export Resolution set to 300ppi—300 x 4.8 = 1440