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

Image Processing Script

Community Beginner ,
Jun 28, 2013 Jun 28, 2013

Copy link to clipboard

Copied

Hi everybody,

this is what I need to do:

All image files from my input folder must be converted to JPEG, RGB, 72dpi and 234 Pixels in width or height.

Source files are TIFF, JPEG or EPS files.

I do not know much about scripting, but I searched the Internet for my purposes and built the follwing script from my search results:

// main settings

var picSourcePath = "C:\\Users\\nolte\\Desktop\\Originale\\";

var picTargetPath = "C:\\Users\\nolte\\Desktop\\Ausgang\\";

var maxSize = 234; // max width and height

//###################################################################################

// save settings and customize environment

var startRulerUnits = app.preferences.rulerUnits;

var startTypeUnits = app.preferences.typeUnits;

var startDisplayDialogs = app.displayDialogs;

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS;

app.displayDialogs = DialogModes.NO;

//var doc = app.activeDocument;

var picFolder = Folder(picSourcePath);

var fileList = picFolder.getFiles();

if (picSourcePath != null && picTargetPath != null) {

    for (var i=0; i<fileList.length; i++) {

        if (fileList instanceof File) {

            open(fileList);

            var newFileName = fileList.name;

            app.activeDocument.changeMode(ChangeMode.RGB);

{       

                // resize

                resize(maxSize);       

                //if (confirm('Sharpen?')) {                       

                //    app.activeDocument.activeLayer.applySharpen();

                //}

                //if (confirm('Save and Close?')) {                       

                    saveWebJpg(newFileName.substring(0, newFileName.length-4) + ".jpg", picTargetPath, 100);

                    //app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

                //}

            }

            // ... and close at all events

            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        }

        }

}

// restore settings

app.preferences.rulerUnits = startRulerUnits;

app.preferences.typeUnits = startTypeUnits;

app.displayDialogs = startDisplayDialogs;

// Funktion um Dokument als Jpeg zu speichern (Fuer Web speichern...)

// Parameter: Dateiname, Pfad mit abschliessendem '\'!, Qualitaet 1-100

function saveWebJpg(jpgName, filePath, jpgQuality ) {

var saveFile = new File(filePath + jpgName);

var webJpgOptions = new ExportOptionsSaveForWeb();

webJpgOptions.format = SaveDocumentType.JPEG;

webJpgOptions.optimized = true;

webJpgOptions.quality = jpgQuality;

activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, webJpgOptions);

File = null; ExportOptionsSaveForWeb = null;

}

function resize(size)

{

  if(app.activeDocument.width > app.activeDocument.height)

    app.activeDocument.resizeImage(size, (size * app.activeDocument.height/app.activeDocument.width),null, ResampleMethod.BICUBIC);

  else

    app.activeDocument.resizeImage((size * app.activeDocument.width/app.activeDocument.height), size, null, ResampleMethod.BICUBIC);

}

The script works fine for JPEG, TIFF and pixel EPS files. The only problem occurs with vector EPS files.

Photoshop opens vector EPS files in low resolution (72dpi), then my script exports these files with the "Save as Web JPG" settings. The output quality of the processed pictures is really bad.

I found out, that there is an "epsOpenOptions" command for Photoshop scripting. I tried to build the following code into my script in order to force Photoshop to open vector EPS files with an resolution of 300dpi. Then the rest of my script shall export these according to my specifications.

// Create a EPS option object [height & width are doc size]

var epsOpenOptions = new EPSOpenOptions

epsOpenOptions.antiAlias = true

epsOpenOptions.mode = OpenDocumentMode.RGB

epsOpenOptions.resolution = 300

epsOpenOptions.page = 3

epsOpenOptions.constrainProportions = true

However, I cannot get this to work and I don't know where I'm wrong. Can anybody help me to modify my script, so that only EPS files will be opened with these options and all other files will be opened as they are?

Thanks in advance!

TOPICS
Actions and scripting

Views

6.1K

Translate

Translate

Report

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

Guru , Jun 28, 2013 Jun 28, 2013

OK… I had a very quick chop about with your code… Try this and see how you get on…

#target photoshop

var picSourcePath = Folder( Folder.desktop + '/Originale' );

var picTargetPath = Folder( Folder.desktop + '/Ausgang' );

var maxSize = 234; // max width and height

var startRulerUnits = app.preferences.rulerUnits;

var startTypeUnits = app.preferences.typeUnits;

var startDisplayDialogs = app.displayDialogs;

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS;

app.displayDi

...

Votes

Translate

Translate
Adobe
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

Try changing this line:

var f = new File('/d/Testout/1meg.jpg');

to this:

var f = new File(Folder.desktop + "/1meg.jpg");

Votes

Translate

Translate

Report

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
Advisor ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

1) There is no way to make a single call so save a jpeg file with a maximum file size. The only way to do it is to try different jpeg quality settings until you get the file size you want. Performance sucks doing this. People have posted bits of code here and maybe on ps-scripts.com that do this. This save-until-you-get-the-correct-size is not available in Image Processor or Image Processor Pro (IPP).

2) I'm the author of IPP. If you have an input file that is giving you problems, send me the original file and what the expected output file should be. I'll see what I can do about fixing the problem. In general, IPP should be able take any input file and export it to any desired file format regardless of the settings of the original or desired settings of the output file.

Votes

Translate

Translate

Report

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 Beginner ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

1) thanks for your reply. I already feared that it's not possible but still hoped that there could be a solution via scripting.

2) IPP is a really good tool. The problem I'm personally having is that - like most other tools - it opens vector eps files in 100% of their size and does not allow to set a minimum width or height before opening.

Example: I have a vector eps file with content in the dimension of 5x5 millimetres. IPP will open it in exactly that size which will lead to no good result if the output file is required larger. Due to the fact that it's vector data, it would be no problem to scale it without any limits, but there is no such feature in IPP.

The script Muppet Mark has written for me opens vector file in high quality (size and resolution) so that the source file is definetely larger than the required output file.

I hoped to find a way to include some kind of loop, so that I can work with the existing (and good working) script and just add a "save-until-you-get-the-correct-size" function.

Votes

Translate

Translate

Report

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
Advisor ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

LATEST

I hoped to find a way to include some kind of loop, so that I can work with the existing (and good working) script and just add a "save-until-you-get-the-correct-size" function.

Set up a loop around the saveWebJpg function that changes the jpgQuality parameter until you get the correct size. I would suggest using an increment size of 5 or 10.

Votes

Translate

Translate

Report

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