Skip to main content
vinoth_mannu
Inspiring
October 11, 2012
Answered

EPS and Tiff files to be converted to JPG

  • October 11, 2012
  • 1 reply
  • 3130 views

Hi All

We requrie to convert eps and tiff files to JPG with the following conditions

Large size  = Reduce 40 % from the orginal.

Medium size = Reduce 25 % from the orginal.

Small size = Reduce 10 % from the orginal.

Keeping 72 dpi for all stages.

Regards,

Vinoth

This topic has been closed for replies.
Correct answer JJMack

You confused me

We requrie to convert eps and tiff files to JPG with the following conditions

Large size  = Reduce 40 % from the orginal.

Medium size = Reduce 25 % from the orginal.

Small size = Reduce 10 % from the orginal.

Keeping 72 dpi for all st

Then where you show the same pixel size for the large and medium

It reduces to 3 types

Large = 40 % Reduction (i.e,) 800 x 389 with 72 dpi

Medium = 25 % Reduction (i.e,) 800 x 389 with 72 dpi

Small = Should be either 75/ 50 with 72

You Code does not seem to make sence to me one hacker to an othere here is what I see.

#target photoshop

var inputFolder = Folder ( 'D:/Work/In/');

var outputFolder = Folder( ['D:/Work/out/'] );

var outputFolder1 = Folder( ['D:/Work/out/Large'] );

var outputFolder2 = Folder( ['D:/Work/out/Medium'] );

var outputFolder3 = Folder( ['D:/Work/out/Small'] );

if (a = fileList)

{

   (filetype= '*.eps')

  }

   else{

   (filetype= '*.tif')

   }

//fileType = ( '*.tif' );

//***You need to understand I'm just a hacker also but above it look to me that  a  and filelist are undefined so filetype will always be set to '*.esp'

if (inputFolder != null && outputFolder != null){

var fileList = inputFolder.getFiles(a);

//**** a still looks undefined to me

    if(fileList.length == 0 )

    {

            alert ("No files found in the folder", "test", "errorIcon")

    }

    else

    {

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

        {

                if (fileList instanceof File && fileList.hidden == false)

                {            

               var jpegOptions = new JPEGSaveOptions()

                jpegOptions.quality = 12;

                jpegOptions.matte = MatteType.NONE

                jpegOptions.embedColorProfile = false

                jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE

//*** quality 12 is overkill 10 should be good

                var docRef = open( fileList )

//*** If you are processing image files and EPS files you may need to test the extension first and have two opens

                app.preferences.rulerUnits = Units.PERCENT

//*** Why percent in you append you stated you wanted pixel sizes in your second append

                docRef.resizeImage (null, null, 300)

//****this changes resolution to 300 DPI why

                docRef.flatten()

//*** not needed for your always using resizeImage below and Photoshop will save a layers document as a flat jpeg file in 8 Bit color mode

                docRef.resizeImage (40, null, 72)

//**** this reduces the documents size to 40% if its original width and maintains its aspect ratio and changes its resoluton setting to 72dpi

               outputFolder1.create();

//*** this would be better outside the loop and sohold be done onle when the folder does not exists

               var newName1 = removeExtension(docRef.name);

docRef.saveAs(new File(outputFolder1+"/"+newName1+".jpg"), jpegOptions, true, Extension.LOWERCASE)

                docRef.resizeImage (62.5, null, 72)

//*** This reduces the 40% sizes document down in size 62.5% so the image  will now be 25% of its original width now I understand your first append

//***  you want to save three resized document jpeg images for each (tif and EPS) file opened.

                outputFolder2.create();

//***Better off outside the loop

               var newName2 = removeExtension(docRef.name);

docRef.saveAs(new File(outputFolder2+"/"+newName2+".jpg"), jpegOptions, true, Extension.LOWERCASE)

//*** you could just use newName1 again

                //app.preferences.rulerUnits = Units.PIXELS

                //docRef.resizeImage (null, 50, 72)

     app.preferences.rulerUnits = Units.PIXELS

     outputFolder3.create();

//*** Again better outside the loop

     var Wid = docRef.width;

     var Hig = docRef.height;

                if (Number(Wid) > 75)

                    {

                         docRef.resizeImage(75,null,);                 

                                           }                                   

                else if(Number(Hig) >= 50)

                    {

                        docRef.resizeImage(null,50,);

                     }

//***I would think some documents may not be resized  in here for by this time a small original image may be <= 75 wide and < the 50 high

//***from you original append you want the last to be 10% of the original so you should have stayed with percent an work out what additional percent would

//***result  in reducing the 25% size to a 10% size of the original. That would be an additional 40% for .25 * .4 = .1 which is 10%

                 app.preferences.rulerUnits = Units.PIXELS

//*** not need done above in fact you should still be using percent

                 //$.writeln (Wid);

                 //$.writeln (Hig);

var newName = removeExtension(docRef.name);

docRef.saveAs(new File(outputFolder3+"/"+newName+".jpg"), jpegOptions, true, Extension.LOWERCASE)

//*** again you could just have used newName1

docRef.close(SaveOptions.DONOTSAVECHANGES)

//var fileObj = File (outputFolder+"/"+newName+".jpg")

//var newfile = fileObj.copy (outputFolder3+"/"+newName+".jpg")

//$.writeln (fileObj1);

//$.writeln (newfile1);

//var newcmd = newname.remove()

//$.writeln (newcmd);

                }

        }

        alert ("Process completed", "test Conversion")   

    }

}

/********************************************************************/

function removeExtension(myDoc)

{

    var str = myDoc.split(".");

    var ext = str[0]

    return ext;

}

/********************************************************************/

/********************************************************************/

function convertRGB()

{

var id11 = charIDToTypeID( "CnvM" );

    var desc4 = new ActionDescriptor();

    var id12 = charIDToTypeID( "T   " );

    var id13 = charIDToTypeID( "RGBM" );

    desc4.putClass( id12, id13 );

    var id14 = charIDToTypeID( "Fltt" );

    desc4.putBoolean( id14, false );

executeAction( id11, desc4, DialogModes.NO );

}

/********************************************************************/

/********************************************************************/

function removeExt(myDoc)

{

    var str = myDoc.split(".");

    var ext = str[1]

    return ext;

}

/********************************************************************/

/********************************************************************/

function removebit(myDoc)

{

    var str = myDoc.split(".");

    var ext = str[1]

    return ext;

}

/********************************************************************/

Message was edited by: JJMack


I cleaned up the script for you try this:

#target photoshop

var orig_ruler_units = app.preferences.rulerUnits;          // Save ruler units

app.preferences.rulerUnits = Units.PERCENT

var inputFolder = Folder ( 'D:/Work/In/');

var outputFolder = Folder( ['D:/Work/out/'] );

var outputFolder1 = Folder( ['D:/Work/out/Large'] );

var outputFolder2 = Folder( ['D:/Work/out/Medium'] );

var outputFolder3 = Folder( ['D:/Work/out/Small'] );

var jpegOptions = new JPEGSaveOptions()

jpegOptions.quality = 10;

jpegOptions.matte = MatteType.NONE

jpegOptions.embedColorProfile = false

jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE

var EPSopts = new EPSOpenOptions();

EPSopts.resolution = 600;

EPSopts.mode = OpenDocumentMode.RGB;

if (inputFolder != null && outputFolder != null){

          var fileList = inputFolder.getFiles(/\.(tif|eps)$/i);

          if(fileList.length == 0 )  {alert ("No files found in the folder");}

          else  {

                    if (!outputFolder.exists) {outputFolder.create();}

                    if (!outputFolder1.exists) {outputFolder1.create();}

                    if (!outputFolder2.exists) {outputFolder2.create();}

                    if (!outputFolder3.exists) {outputFolder3.create();}

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

                              //alert("File  = " + fileList);

                              // Isolate Image name

                              var Name =  decodeURI(fileList).replace(/\.[^\.]+$/, '');// strip the extension off

                              var imagePath = "";

                              while (Name.indexOf("/") != -1 ) {                          // Strip Path

                                        imagePath= imagePath + Name.substr(0, Name.indexOf("/") + 1);

                                        Name = Name.substr(Name.indexOf("/") + 1 ,);

                                        }

                              var ext =  decodeURI(fileList);

                              ext=ext.substring(ext.length-3,);

                              if (ext=="eps" || ext=="EPS" ){var docRef = open( fileList,EPSopts);}

                              else{ var docRef = open( fileList );}

                              docRef.flatten()  // May not be needed

                              docRef.resizeImage (40, null, 72);

                              docRef.saveAs(new File(outputFolder1+"/"+Name+".jpg"), jpegOptions, true, Extension.LOWERCASE);

                              docRef.resizeImage (62.5, null, 72);

                              docRef.saveAs(new File(outputFolder2+"/"+Name+".jpg"), jpegOptions, true, Extension.LOWERCASE);

                              docRef.resizeImage (40, null, 72);

                              docRef.saveAs(new File(outputFolder3+"/"+Name+".jpg"), jpegOptions, true, Extension.LOWERCASE);

                              docRef.close(SaveOptions.DONOTSAVECHANGES);

                              }

                    alert ("Process completed");

                    }

          }  

app.preferences.rulerUnits = orig_ruler_units;                    // Restore ruler units

Message was edited by: JJMack

1 reply

c.pfaffenbichler
Community Expert
Community Expert
October 11, 2012

So what is the question?

And what constitutes »Large size« etc.?

vinoth_mannu
Inspiring
October 11, 2012

Hi,

Please find the below script which reduced the orginal image.

Orginal  image for Ex. The image size is 2000 px (Widht) x 972 px (height) 300 dpi

It reduces to 3 types

Large = 40 % Reduction (i.e,) 800 x 389 with 72 dpi

Medium = 25 % Reduction (i.e,) 800 x 389 with 72 dpi

Small = Should be either 75/ 50 with 72

The Script follows :

    #target photoshop

    inputFolder = Folder.selectDialog("Select a folder contains '*.tif' files ");
    //var inputFolder = Folder ( 'D:/Work/In/');
    //var outputFolder4 = Folder( [inputFolder] );
    var outputFolder1 = Folder( ['D:/Work/out/Large'] );
    var outputFolder2 = Folder( ['D:/Work/out/Medium'] );
    var outputFolder3 = Folder( ['D:/Work/out/Small'] );
    if (inputFolder != null ){
    fileType = ( '*.tif' );
    //$.writeln(inputFolder);
    //$.writeln(outputFolder4);
    var fileList = inputFolder.getFiles(fileType);
                   
        if(fileList.length == 0 )
        {
                alert ("No files found in the folder", "test", "errorIcon")
        }
        else
        {
            for (var i = 0; i < fileList.length; i++)
            {
                    if (fileList instanceof File && fileList.hidden == false)
                    {            
                   var jpegOptions = new JPEGSaveOptions()
                    jpegOptions.quality = 12;
                    jpegOptions.matte = MatteType.NONE
                    jpegOptions.embedColorProfile = false
                    jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE 

                    var docRef = open( fileList )
                    app.preferences.rulerUnits = Units.PERCENT
                    docRef.resizeImage (null, null, 300)
                    docRef.flatten()
                    //outputFolder4.create();
                                 
                    docRef.resizeImage (40, null, 72)
                   outputFolder1.create();
                   var newName1 = removeExtension(docRef.name);
     docRef.saveAs(new File(outputFolder1+"/"+newName1+".jpg"), jpegOptions, true, Extension.LOWERCASE)

                    
                    docRef.resizeImage (62.5, null, 72)
                    outputFolder2.create();
                   var newName2 = removeExtension(docRef.name);
     docRef.saveAs(new File(outputFolder2+"/"+newName2+".jpg"), jpegOptions, true, Extension.LOWERCASE)

                    //app.preferences.rulerUnits = Units.PIXELS
                    //docRef.resizeImage (null, 50, 72)
        
         app.preferences.rulerUnits = Units.PIXELS
         outputFolder3.create();

    var theTargetDiag = 75/ 50;
    var Wid = docRef.width;
    var Hig = docRef.height;
    var theDiag = Wid / Hig;
    if (theDiag >= theTargetDiag) {
    docRef.resizeImage(new UnitValue (75, "px"),null);                
    }                                  
    else {
    docRef.resizeImage(null, new UnitValue (50, "px"));
    };    
                                                   
    var newName = removeExtension(docRef.name);
    
    docRef.saveAs(new File(outputFolder3+"/"+newName+".jpg"), jpegOptions, true, Extension.LOWERCASE)

    docRef.close(SaveOptions.DONOTSAVECHANGES)

    //var fileObj = File (outputFolder+"/"+newName+".jpg")
    //var newfile = fileObj.copy (outputFolder3+"/"+newName+".jpg")
    //$.writeln (fileObj1);
    //$.writeln (newfile1);
    //var newcmd = newname.remove()
    //$.writeln (newcmd);
     
    
                    }
            }
            alert ("Process completed", "test")   
        }
    }

    /********************************************************************/
    function removeExtension(myDoc)
    {
        var str = myDoc.split(".");
        var ext = str[0]
        return ext;
    }
    /********************************************************************/

    /********************************************************************/
    function convertRGB()
    {
    var id11 = charIDToTypeID( "CnvM" );
        var desc4 = new ActionDescriptor();
        var id12 = charIDToTypeID( "T   " );
        var id13 = charIDToTypeID( "RGBM" );
        desc4.putClass( id12, id13 );
        var id14 = charIDToTypeID( "Fltt" );
        desc4.putBoolean( id14, false );
    executeAction( id11, desc4, DialogModes.NO );
    }
    /********************************************************************/

    /********************************************************************/
    function removeExt(myDoc)
    {
        var str = myDoc.split(".");
        var ext = str[1]
        return ext;
    }
    /********************************************************************/

    /********************************************************************/
    function removebit(myDoc)
    {
        var str = myDoc.split(".");
        var ext = str[1]
        return ext;
    }
    /********************************************************************/

This works fine for Tif files, But for EPS I am unable to add or execute

Please let me know if you need any further queries.

Regards,

Vinoth

JJMack
Community Expert
Community Expert
October 11, 2012

vinoth_mannu wrote:

Orginal  image for Ex. The image size is 2000 px (Widht) x 972 px (height) 300 dpi

It reduces to 3 types

Large = 40 % Reduction (i.e,) 800 x 389 with 72 dpi

Medium = 25 % Reduction (i.e,) 800 x 389 with 72 dpi

Small = Should be either 75/ 50 with 72

To me it looks like you actually want two output image size ranges and most likely want to retain the original document aspect ratio and have all output documents to have a 72dpi resolution.

Looks straight forward to me.

Start with saveing ruler units and set unites to pixels

images resize null null 72 make all documents have a 72 dp resolutioni.

test the originale images size to see if it should be resized to the large or small output size

for the large size documents use FitImage 800 800 for small document use FitImage 75 75.

restore ruler units to it original saved setting

Here is code from the Image Processor Script to use Automat plugin FitImage.

// use the fit image automation plug-in to do this work for me

function FitImage( inWidth, inHeight ) {

          if ( inWidth == undefined || inHeight == undefined ) {

                    alert( strWidthAndHeight );

                    return;

          }

          var desc = new ActionDescriptor();

          var unitPixels = charIDToTypeID( '#Pxl' );

          desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );

          desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );

          var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );

          executeAction( runtimeEventID, desc, DialogModes.NO );

}

JJMack