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

Script to resize an image and move to specific spot

Participant ,
Jun 26, 2021 Jun 26, 2021

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
2.7K
Translate
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

 

 

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

 

 

 

Translate
Participant ,
Jun 26, 2021 Jun 26, 2021

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

Translate
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

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

 

 

Translate
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

 

 

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

 

 

 

Translate
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

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?

Translate
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

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?

Translate
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

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

Translate
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

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.

Translate
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

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. 

Translate
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
LATEST

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

Translate
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