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

Need Help with Script to resize a single photo

Participant ,
Dec 31, 2019 Dec 31, 2019

Hello:
I get a number of photos that need to be mug shot size, and I'm new to scripting.
I have this but when I run it, nothing happens, so I know I've got something wrong.

But I'm at a loss of what to do to correct the issue.  I've tried several different syntex, but I get error messages when I change things.

Any help would be appreicated.

Thanks, Larry
var mySelection = app.selection;
mySelection = mySelection.geometricBounds = ["0.7303 in", "1.0889 in"];

TOPICS
Scripting
510
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 1 Correct answer

Community Expert , Dec 31, 2019 Dec 31, 2019

Hi Larry,

Try the following code, by selecting the rectangle that contains the image

 

var mySelection = app.selection[0];
var gm = mySelection.geometricBounds
//Save the value, and set it to inches
var origUnit = app.scriptPreferences.measurementUnit
app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES
mySelection.geometricBounds = [gm[0], gm[1], gm[0] + 0.7303, gm[1] + 1.0889];
mySelection.fit(FitOptions.CONTENT_TO_FRAME)
//Restore the value
app.scriptPreferences.measurementUnit = o
...
Translate
Community Expert ,
Dec 31, 2019 Dec 31, 2019

Hi Larry,

Try the following code, by selecting the rectangle that contains the image

 

var mySelection = app.selection[0];
var gm = mySelection.geometricBounds
//Save the value, and set it to inches
var origUnit = app.scriptPreferences.measurementUnit
app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES
mySelection.geometricBounds = [gm[0], gm[1], gm[0] + 0.7303, gm[1] + 1.0889];
mySelection.fit(FitOptions.CONTENT_TO_FRAME)
//Restore the value
app.scriptPreferences.measurementUnit = origUnit

 

In your code you tried to change the geometricBounds of app.selection, however app.selection is a collection of objects. So i used just one of the objects of the selection using app.selection[0], if you have multiple items in selection you can get reference to them using the index likeapp.selection[0], app.selection[1] etc

 

GemetricBounds is an array with values like [y1, x1, y2, x2] giving the coordinates of top, left and bottom, right points. So you need to keep the top, left the same and add values to the bottom right to resize the rectangle. Now once that is done we also need to fit the image inside the rectangle, here i used the Content to Frame option you can choose any of the available values

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#FitOptions.html

 

Also all this can be done using the resize method of rectangle as well, try it

https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#Rectangle.html#d1e217191__d1e22...

 

-Manan

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 ,
Dec 31, 2019 Dec 31, 2019

Wow! That worked.
Thanks so much, Manan.
I've been banging my head against the wall trying to figure this out.

Thanks again.

Larry

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 ,
Jan 01, 2020 Jan 01, 2020

Also, the bounds are an array of numbers [y1, x1, y2, x2]. If for some reason you do not want to set and reset the measurement prefs, it is possible to coerce the numbers into a string and use "in" as you did in your first post:

 

 

 

var mySelection = app.selection[0];
var gm = mySelection.geometricBounds
//1.0889" width x .7303" height
mySelection.geometricBounds = [gm[0], gm[1], (gm[0] + 0.7303 ).toString() + " in", (gm[1] + 1.0889).toString() + " in"];

 

 

 

 

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 ,
Jan 01, 2020 Jan 01, 2020
LATEST

Thanks, Rob:
This is great...It worked.  I've been trying, unsuccesfully, for several days to get my script to work, trying different configurations, and none worked.

I appreciate you helping me out.

Thanks again, 
Larry

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