Legend
April 26, 2026
Answered
How to obtain the original height/width ratio of an image?
- April 26, 2026
- 4 replies
- 149 views
There was originally a piece of code used to obtain the height and width of an image.
I found that when an image is distorted in InDesign, using this aspect ratio calculation is incorrect.
This code can only be used to obtain the "usable width" of the image in the ID.
Cannot execute s.redefineScaling([1, 1]);Because it may be a design requirement at this point.
How to obtain the original height/width ratio of an image?
Thank you.
var image = app.activeDocument.selection[0];
var imagePath = image.itemLink.filePath;
var myResolution = 350;
var hScale = image.horizontalScale * (myResolution / image.actualPpi[0]);
var vScale = image.verticalScale * (myResolution / image.actualPpi[1]);
app.preferences.rulerUnits = Units.MM;
var myFile = new File(imagePath);
var myDoc = app.open(myFile);
myDoc.resizeImage(undefined, undefined, myResolution, ResampleMethod.NONE);
var w = myDoc.width.value * hScale * 0.01;
var h = myDoc.height.value * vScale * 0.01;



