• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
7

Script to resize frame and image

Community Beginner ,
Jan 17, 2024 Jan 17, 2024

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!!scaleQ.jpg   

TOPICS
Scripting

Views

740

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 18, 2024 Jan 18, 2024

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
...

Votes

Translate

Translate
Community Expert ,
Jan 17, 2024 Jan 17, 2024

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).

Mike Witherell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 17, 2024 Jan 17, 2024

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....

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2024 Jan 17, 2024

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.

Mike Witherell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 17, 2024 Jan 17, 2024

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 18, 2024 Jan 18, 2024

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:
Screen Shot 4.png
 
After:
Screen Shot 5.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 18, 2024 Jan 18, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines