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

Resize and export out .ai to png using a script in Photoshop (MAC Issue)

New Here ,
May 08, 2024 May 08, 2024

I'm working on a Mac in Photoshop 2024 and am using the below script to pull an .ai file from a set of folders and export it out as a png that is 1154px wide but keeps its apsect ratio vertically. Then it should export that .png file back out in the same folder that it exported the .ai file from. The below works fine on PC, but on MAC it skews the aspect ratio for some of the exported .png files and it also changes some of the colour logos to grayscale. Does anyone have any suggestions as to why it would do that?

 

 

// Function to process AI files in a folder and its subfolders
function processAIFiles(folder) {
var files = folder.getFiles();
for (var i = 0; i < files.length; i++) {
if (files[i] instanceof Folder) {
// Recursive call for subfolders
processAIFiles(files[i]);
} else if (files[i] instanceof File && files[i].name.match(/\.ai$/i)) {
var doc = app.open(files[i]);
if (doc) {
// Change width to 1154px
var newWidth = 1154;
var newHeight = (newWidth / doc.width) * doc.height;

// Set resolution to 300 dpi
doc.resizeImage(newWidth, newHeight, 300, ResampleMethod.BICUBICSHARPER);

// Save as PNG
var pngOptions = new PNGSaveOptions();
pngOptions.quality = 12; // High quality
var pngFile = new File(files[i].parent + "/" + doc.name.replace(".ai", ".png"));
doc.saveAs(pngFile, pngOptions);

// Close the document without saving changes to AI file
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
}

TOPICS
Bug , Scripting
733
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 1 Correct answer

Enthusiast , May 08, 2024 May 08, 2024

Try the following steps on Mac OS
1) Manually open any of the .ai files in Photoshop and set the color mode, aspect ratio settings.
2) Close the file
3) Run the script

SergeyOsokin_1-1715234309314.png
I think Photoshop opens your files with the latest Import PDF window settings when the script runs.

At least it worked for me. At first your script exported distorted proportions. But after the steps you took, the script miraculously worked.

 

 

Translate
Adobe
Enthusiast ,
May 08, 2024 May 08, 2024

Try the following steps on Mac OS
1) Manually open any of the .ai files in Photoshop and set the color mode, aspect ratio settings.
2) Close the file
3) Run the script

SergeyOsokin_1-1715234309314.png
I think Photoshop opens your files with the latest Import PDF window settings when the script runs.

At least it worked for me. At first your script exported distorted proportions. But after the steps you took, the script miraculously worked.

 

 

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
New Here ,
May 16, 2024 May 16, 2024
LATEST

OMG Thank you! This sorted it! Will remember this going forward!!

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