Copy link to clipboard
Copied
Hello. I need help in my script.
I need to open the AI file and resize it.
var pdfOptions = new PDFOpenOptions();
pdfOptions.mode=OpenDocumentMode.RGB;
app.open(BlueFile,pdfOptions);
My script for opening file work ok. Than i want resize my image.But a bit different.
I want to resize the image while maintaining the aspect ratio. so that the height never exceeds 1100px and the width is not over 700px.
this is my current script for resizing. But he does not limit the value.
var bounds = app.activeDocument.activeLayer.bounds;
var width = bounds[2].value - bounds[0].value;
var height = bounds[3].value - bounds[1].value;
var newSize;
if(width >= height){
var MAXSIZE=700;
newSize = (100 / width) * MAXSIZE;
} else {
var MAXSIZE=1100;
newSize = (100 / height) * MAXSIZE;
}
app.activeDocument.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
the image below shows how my script is currently working
But i want size of image like that ( when get Widht at 700px stop resizing)
Copy link to clipboard
Copied
Photoshop ships with a script. A Photoshop Plug it has a dialog and it has Action support programmed in to bypass its dialog when executed in an action step its name is Fit Image. You set the max Width and max Height the script will resize an image to fit within that area. If the image has the same aspect ratio it will be resized to that width and height either upsize of down size the image. If the image does not have the same aspect ratio the image will be resized to fit with in that area either upsize or down size. The image height or width will be what you set and the other side will be less than what you set. The image's Aspect ratio will not change the image will fit within the area but not fill the area. That what Fit image image does. All you need to do is read its code to see the answer.
Copy link to clipboard
Copied
preferences.rulerUnits = Units.PIXELS; with(activeDocument.activeLayer) resize
(mm = Math.min(700 / ((b = bounds)[2] - b[0]), 1100 / (b[3] - b[1])) * 100, mm)