Skip to main content
Inspiring
September 8, 2020
解決済み

How to resize the image size by percentage ?

  • September 8, 2020
  • 返信数 6.
  • 2640 ビュー

DEAL ALL,

GREETINGS!

 

I'm facing a small problem. There is aproject i'm developing script for. Anyhow, the designers asked me somthing and since I'm not a designr, so I don't have a clue how to do it from the UI so i can understand how to do it wit script.

 

So, they asked me to decrese the size of image to make it 30% because the current size is 50%. It's applicable with code? i dont even changed the size of image! i Just place the image and use the fit functons to make it smaller and better, check my code, below:

var doc = app.documents.add()
			
			var image = File.openDialog("Please try to select the icons folder");
		
			
			var rect1 = doc.pages[0].textFrames.add({
				geometricBounds:  [12.7, 12.7, 90, 90]
			});

			rect1.place(image)
			rect1.fit(FitOptions.PROPORTIONALLY)
			rect1.fit(FitOptions.FRAME_TO_CONTENT)

			app.activeWindow.viewDisplaySetting = ViewDisplaySettings.HIGH_QUALITY;

However, is it possiable to decrease the image size by percentege? and how?

I'm using JS.

Thanks all.

このトピックへの返信は締め切られました。
解決に役立った回答 Sunil Yadav

You can try this below sample script:

var doc = app.documents.add();
var image = File.openDialog("Please try to select the icons folder");
var rect1 = doc.pages[0].textFrames.add({
    geometricBounds:  [12.7, 12.7, 90, 90]
});
rect1.place(image);
rect1.fit(FitOptions.PROPORTIONALLY);
rect1.fit(FitOptions.FRAME_TO_CONTENT);
rect1.graphics[0].absoluteHorizontalScale = 30;
rect1.graphics[0].absoluteVerticalScale = 30;
rect1.fit(FitOptions.FRAME_TO_CONTENT);
app.activeWindow.viewDisplaySetting = ViewDisplaySettings.HIGH_QUALITY;

Best

Sunil

返信数 6

Sunil Yadav
Sunil Yadav解決!
Legend
September 9, 2020

You can try this below sample script:

var doc = app.documents.add();
var image = File.openDialog("Please try to select the icons folder");
var rect1 = doc.pages[0].textFrames.add({
    geometricBounds:  [12.7, 12.7, 90, 90]
});
rect1.place(image);
rect1.fit(FitOptions.PROPORTIONALLY);
rect1.fit(FitOptions.FRAME_TO_CONTENT);
rect1.graphics[0].absoluteHorizontalScale = 30;
rect1.graphics[0].absoluteVerticalScale = 30;
rect1.fit(FitOptions.FRAME_TO_CONTENT);
app.activeWindow.viewDisplaySetting = ViewDisplaySettings.HIGH_QUALITY;

Best

Sunil

salshaw749作成者
Inspiring
September 9, 2020

THANKS!!! IT WORKED PERFICTILYY 

rob day
Community Expert
Community Expert
September 8, 2020

I think you have to consider the actual dimensions of the placed image, and if you want to keep the bounds of the .rect1 frame unchanged.

 

For example here are two cases: on the left the image’s actual dimensions are 18" x 24", and when it is scaled by 30% centered, it fits in the frame. The version on the right has a starting image dimension of 5" x 7", and when it is scaled by 30% it is smaller than the frame—in this case you could fit the frame to the image, but that would change the bounds of the original rectangle.

 

 

To place centered you can set the transform reference point with this:

 

 

app.layoutWindows[0].transformReferencePoint = AnchorPoint.CENTER_ANCHOR;

 

 

SychevKA
Inspiring
September 8, 2020

I think it's enough to change frame size.
90 - 12.7 = 77.3
but it's only 50℅ ...
ok! 77.3 * 2 = 154.6
we need 30℅, i.e.
154.6 * 30 / 100 = 46.38 + 12.7 = 59.08
and now we can write:
geometricBounds: [12.7, 12.7, 59.08, 59.08]

 

salshaw749作成者
Inspiring
September 9, 2020

Thanks! The calcultion, worked fine and decresed the size of image, because i changed the frame size. Thanks so much

rob day
Community Expert
Community Expert
September 8, 2020

You can scale either the image or its parent frame using the absoluteHorizontalScale and absoluteVerticalScale properties. This scales the image.

 

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

 

 


var doc = app.documents.add()
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
			
var image = File.openDialog("Please try to select the icons folder");
var rect1 = doc.pages[0].rectangles.add({geometricBounds:  [12.7, 12.7, 90, 90]});

rect1.place(image);
rect1.images[0].absoluteHorizontalScale = 30;
rect1.images[0].absoluteVerticalScale = 30;
app.activeWindow.viewDisplaySetting = ViewDisplaySettings.HIGH_QUALITY;

 

 

salshaw749作成者
Inspiring
September 9, 2020

Thanks for sharing with me your work, I've tried it, but since we have many images so the size will vary, so some image worked and the others alert me that the value "30" would cause one or more object to leave  the pasteborder. Anyhow, thanks for you time and suport.

Legend
September 8, 2020
salshaw749作成者
Inspiring
September 9, 2020

Thanks!

Derek Cross
Community Expert
Community Expert
September 8, 2020

You can reduce the page size by a percentage, manually, in the Adjust Layout feature.