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

Script to resize an image and move to specific spot

Participant ,
Jun 26, 2021 Jun 26, 2021

Copy link to clipboard

Copied

I have a lot of jobs where I need to have the specific size image at the top of an A4 page with 3mm bleed.

 

Just wondering if it's possible to have a script that i can execute with an image selected on the page and it sizes it to 216mm width, 116.522mm height, and set the Y coordinate to 55.261mm. Also if it could centre the image horizontally to the page that would be great also (don't think this can be done with the x coordinate because it might change depending if its a pages vs spreads layout?).

 

Any help with this would be greatly appreciated, thanks! 

 

Example:

danielw42205661_1-1624770278321.png

 

 

TOPICS
Scripting

Views

1.7K

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 2 Correct answers

Community Expert , Jun 27, 2021 Jun 27, 2021

You can set the size and position in the object styles.

 

Just apply the object style to the image you want.

Window>Styles>Object Styles

EugeneTyson_0-1624781861124.png

 

And scroll down the menu on the left

EugeneTyson_1-1624781886003.png

 

 

Votes

Translate

Translate
Community Expert , Jun 27, 2021 Jun 27, 2021

 

 

Select the image frame:

 

var y = 55.261; var h = 116.522; var w = 216;

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
var pw = app.documents.item(0).documentPreferences.pageWidth;
app.documents.item(0).selection[0].geometricBounds = [y, pw-w, y + h, w];
app.documents.item(0).selection[0].fit(FitOptions.PROPORTIONALLY);

 

 

 

Votes

Translate

Translate
Participant ,
Jun 26, 2021 Jun 26, 2021

Copy link to clipboard

Copied

Sorry forgot to mention, if it could fill frame proportionally after the resize that would be great too. 

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

You can set the size and position in the object styles.

 

Just apply the object style to the image you want.

Window>Styles>Object Styles

EugeneTyson_0-1624781861124.png

 

And scroll down the menu on the left

EugeneTyson_1-1624781886003.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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

 

 

Select the image frame:

 

var y = 55.261; var h = 116.522; var w = 216;

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
var pw = app.documents.item(0).documentPreferences.pageWidth;
app.documents.item(0).selection[0].geometricBounds = [y, pw-w, y + h, w];
app.documents.item(0).selection[0].fit(FitOptions.PROPORTIONALLY);

 

 

 

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

That's fantastic.

 

Just wondering if the style route is better as you could tweak the position and all would update.

 

Does the script do that?

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

I don’t think you can set a specific x or y position with a style unless the image is anchored in a text flow?

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

I think it does work. I will have to try tomorrow

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

Yes, you’re right. I forget about the size and position option, which got added a few versions back, and which I obviously never use.

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
Participant ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

Thanks Rob. Although it does size and fit the frame correctly, it doesn't move it to the top of the page for me. Did you test it and it worked for you? I'm on CC 2019 so not sure if that's a factor for it not working. 

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
Participant ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

LATEST

Nevermind, figure out i had to set Y to -3. Then it puts it in the right spot. Thanks Rob!!!

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