Skip to main content
Bedazzled532
Inspiring
October 8, 2023
Answered

Resize Image script

  • October 8, 2023
  • 2 replies
  • 2809 views

I have several images in my document. My document width is 80mm.

 

I have lots of images to be placed.

 

I have created an object style which resizes the image frame to 80mm and fit the content proportionally.

Issue is that there is no option in object style to resize it proportionally height wise.

 

Is there any script which takes the dimensions of the image and then size is widthwise to 80mm and changes its height proportionally ?

 

Thanks

Correct answer rob day

@rob day Hi Rob

 

Just one issue which I noticed. Nothing major. I am attaching 3 photos. Before, after and Should_be.

There should not be any space before the "After" image. My final result should be like  "should_be" image.

Thanks

 


Try adding this at the end:

 

frame.move([m,m]);

2 replies

rob day
Community Expert
Community Expert
October 8, 2023

My document width is 80mm.

 

Hi @Bedazzled532 , If you are trying to set the frame to fill your document page, you can get the parent page’s bounds rather than hard coding a number. Something like this:

 

var frame = app.activeDocument.selection[0];
//set the frame’s bounds to match its parent page bounds
frame.geometricBounds = frame.parentPage.bounds
frame.fit(FitOptions.PROPORTIONALLY);
Bedazzled532
Inspiring
October 8, 2023

Hi Rob
Thanks for the reply.

Actually I am working on a long document with letter-half size.
I have given a margin of .75" all sides. Effective size for text to flow is 4 inches.

Text flow is fine. Some topics require images in between the text.

I want to place the image and run the script to resize its width to 4" and anchor it or use inline anchor.

The script will also apply an object style named "picture".

I am using this code to achieve that:

//Apply an object style to the selection
frame.applyObjectStyle(app.activeDocument.objectStyles.itemByName("picture"));

I have used your code. Its maximizing the image to the document size. I want it to be exactly the margin size. 4" in this case.

Secondly, I wanted to apply a single undo system using the doScript method which is not working.

Bedazzled532
Inspiring
October 9, 2023

Try adding this at the end:

 

frame.move([m,m]);

Thanks. It worked.

Bedazzled532
Inspiring
October 8, 2023

I have written this script which seems to be working. I need tips to make this script better. Like I have hardcoded 80mm as my final width in the code. How to make it more dynamic?

var frame = app.activeDocument.selection[0];
var b = frame.geometricBounds;

//Record Original width and height
var origWidth = b[3]-b[1];
var origHeight = b[2]-b[0];

//Find the percentage change
//80mm is the new width

percentChange = ((80-origWidth)/origWidth)*100;

wChange = origWidth + (origWidth*(percentChange/100));
hChange = origHeight + (origHeight*(percentChange/100));


// Resize the frame
    frame.geometricBounds = [
        frame.geometricBounds[0], // Top coordinate
        frame.geometricBounds[1], // Left coordinate      
		frame.geometricBounds[0] + hChange, // Bottom coordinate
        frame.geometricBounds[1] + wChange // Right coordinate
    ];

frame.fit(FitOptions.PROPORTIONALLY);