My fist script - Any serious errors?
Hello,
here is my first feeble attempt of scripting. I'm trying to change resolution to 300, then resize image and lastly resize again if print width/height is too large.
docRef = app.activeDocument;
var startDisplayDialogs = app.displayDialogs;
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
displayDialogs = DialogModes.NO;
preferences.rulerUnits = Units.PIXELS;
preferences.typeUnits = TypeUnits.PIXELS;
if (parseFloat(app.activeDocument.width) >= parseFloat(app.activeDocument.height))
{
//check if image is square (or close enough)
if (parseFloat(app.activeDocument.height) >= parseFloat(app.activeDocument.width) * 0.9)
{
var square = true;
}
else
{
var square = false;
}
}
else
{
if (parseFloat(app.activeDocument.width) >= parseFloat(app.activeDocument.height) * 0.9)
{
var square = true;
}
else
{
var square = false;
}
}
if (parseFloat(app.activeDocument.height) >= parseFloat(app.activeDocument.width))
{
//change resolution
docRef.resizeImage(undefined, undefined, 300, ResampleMethod.NONE);
//resize image
docRef.resizeImage(undefined, 3543, undefined, ResampleMethod.BICUBIC);
var printWidth = parseFloat(app.activeDocument.width) / app.activeDocument.resolution;
//resize if print width is longer than 8.35 inch and image isn't square
if (printWidth > 8.35 && square == false)
{
docRef.resizeImage(2505, undefined, undefined, ResampleMethod.BICUBIC);
}
}
else
{
docRef.resizeImage(undefined, undefined, 300, ResampleMethod.NONE);
docRef.resizeImage(3543, undefined, undefined, ResampleMethod.BICUBIC);
var printHeight = parseFloat(app.activeDocument.height) / app.activeDocument.resolution;
if (printHeight > 8.35 && square == false)
{
docRef.resizeImage(undefined, 2505, undefined, ResampleMethod.BICUBIC);
}
}
//save changes and close image
app.activeDocument.close(SaveOptions.SAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
app.preferences.typeUnits = startTypeUnits;
app.displayDialogs = startDisplayDialogs;
Any sense at all?
Any serious errors?
thanks ![]()