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

How to resize the image size by percentage ?

Participant ,
Sep 08, 2020 Sep 08, 2020

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.

TOPICS
Activation billing and install , Bug , EPUB , Feature request , How to , Import and export , InCopy workflow , Performance , Print , Publish online , Scripting , SDK , Sync and storage , Type
2.5K
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

Participant , Sep 08, 2020 Sep 08, 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]

 

Translate
Advocate , Sep 08, 2020 Sep 08, 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 = Vi
...
Translate
Community Expert ,
Sep 08, 2020 Sep 08, 2020

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

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
Mentor ,
Sep 08, 2020 Sep 08, 2020
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 ,
Sep 09, 2020 Sep 09, 2020

Thanks!

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 ,
Sep 08, 2020 Sep 08, 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;

 

 

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 ,
Sep 09, 2020 Sep 09, 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.

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 ,
Sep 08, 2020 Sep 08, 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]

 

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 ,
Sep 09, 2020 Sep 09, 2020

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

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 ,
Sep 08, 2020 Sep 08, 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.

 

Screen Shot 8.png

 

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

 

 

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

 

 

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
Advocate ,
Sep 08, 2020 Sep 08, 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

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 ,
Sep 09, 2020 Sep 09, 2020
LATEST

THANKS!!! IT WORKED PERFICTILYY 

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