Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2003
    Location
    Byckeye, AZ
    Posts
    804

    Changing ppi with a custom tool

    I'm not too sure if I should be asking this in the programming forums or the Photoshop forum, but here goes;

    So I'm putting together my first script for a custom tool in Photoshop right now. The goal is to create a tool I can use in a batch process to go through a folder with thousands of images and change the ppi. On anything larger than 300 I want to change it down to 300, but for anything with less than 300ppi I want it to just close the file without saving. I only want to change the ppi and leave the original dimensions the same (changing the ppi without shrinking or enlarging the photo).

    Right now I've got a script that will change the ppi to 300, but I'm not sure how to write the "if , else" instructions to run the steps on only images with a resolution higher than 300ppi.

    I'm new to javascript, so if you know the answer... use small words

    Anyone know what the condition is called to reference the resolution in a script?

  2. #2
    Join Date
    May 2014
    Posts
    103
    this could not be done via droplets?

    I have no clue regarding the photoshop javascript API, just glanced over it...

    Code:
    var pdfOpenOptions = new PDFOpenOptions
    
    if (300 < pdfOpenOptions.resolution) {
           // do some damage here
           // like change ppi
           pdfOpenOptions.resolution = 300
    }
    edit reason, this is not a pseudo code anymore, and the forgot to include the PDFOpenOptions inside the code
    Last edited by crscutas; 07-02-2014 at 06:05 PM.

  3. #3
    Join Date
    Mar 2003
    Location
    Byckeye, AZ
    Posts
    804
    First, thanks for the reply. Second, please pardon my ignorance. I have no idea even what droplets are... can you clue me in on that?

    I've been working as a professional artist for some time now and just today I found that I need start building some new tools for my job. I'm learning on the fly, so...
    Draw a picture? Sure.
    Make a 3D Model? No problem.
    Write a custom script for a new tool? What for be a scrupt is?

    Help me out here too; pdfOpenOptions. Is that specific to a PDF file format or is that generic in reference to resolutions across the board in Photoshop?

  4. #4
    Join Date
    May 2014
    Posts
    103
    No Problem I HAVE A MADE A BIG MISTAKE THOUGH I was in hurry to give you an answer (very wrong of me) that example was for the pdf, and will not work for your problem... but the if statement should look like that I will look into this more when I get to work.

    I have no experience writing tools for photoshop so I don't really know exactly what that is... I wish I could test it out first, but I am now eating breakfast

    this was the scripting guide i was looking at prior to answering your question
    http://wwwimages.adobe.com/content/d...ting-guide.pdf

    I have not done droplets for a long time. So I don't if that still exist T_T

    Droplets is an automation tool. what it is, is a recording of the actions that you made of a certain image. If you already have a Droplet that resizes images to 50% of their size, so you can just drag and drop all the image to that droplet and photoshop will do the resizing for you.

    ------------------
    so much negativity in this post, like I have not, I don't know *sad face* im running late

  5. #5
    Join Date
    Mar 2003
    Location
    Byckeye, AZ
    Posts
    804
    Thanks for the feedback so far... I'm learning quite a bit through this exercise.

    Okay, I've come up with a partial solution (feel free to pick this apart and let me know what I should have done differently) which will allow me to process an image at a time... saving a lot of mousing and clicking at least. I am still looking for code for selecting a folder and running the process as a batch, but here's what I've got so far;

    Code:
    #target photoshop
    
    //Select Folder - not sure how to do that yet
    
    //Batch process - also no idea how to do that yet
    
    // Convert image to 300ppi
    
    if (app.activeDocument.resolution > 300.00000 )
    {
    var idImgS = charIDToTypeID( "ImgS" );
        var desc2 = new ActionDescriptor();
        var idHght = charIDToTypeID( "Hght" );
        var idWdth = charIDToTypeID( "Wdth" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc2.putUnitDouble( idWdth, idPrc, 100.000000 );
        desc2.putUnitDouble( idHght, idPrc, 100.000000 );
        var idRslt = charIDToTypeID( "Rslt" );
        var idRsl = charIDToTypeID( "#Rsl" );
        desc2.putUnitDouble( idRslt, idRsl, 300.000000 );
        var idscaleStyles = stringIDToTypeID( "scaleStyles" );
        desc2.putBoolean( idscaleStyles, true );
        var idCnsP = charIDToTypeID( "CnsP" );
        desc2.putBoolean( idCnsP, true );
        var idIntr = charIDToTypeID( "Intr" );
        var idIntp = charIDToTypeID( "Intp" );
        var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
        desc2.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
    executeAction( idImgS, desc2, DialogModes.NO );
    }
    //Reduce Dimensions of files larger than 5000px wide     
    if (app.activeDocument.width > 5000)
    {
    var idImgS = charIDToTypeID( "ImgS" );
        var desc15 = new ActionDescriptor();
        var idWdth = charIDToTypeID( "Wdth" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc15.putUnitDouble( idWdth, idPrc, 50.000000 );
        var idscaleStyles = stringIDToTypeID( "scaleStyles" );
        desc15.putBoolean( idscaleStyles, true );
        var idCnsP = charIDToTypeID( "CnsP" );
        desc15.putBoolean( idCnsP, true );
        var idIntr = charIDToTypeID( "Intr" );
        var idIntp = charIDToTypeID( "Intp" );
        var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
        desc15.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
    executeAction( idImgS, desc15, DialogModes.NO );
    app.activeDocument.close(SaveOptions.SAVECHANGES);
    }
    
    else 
    
    {
    //Save and Close
    app.activeDocument.close(SaveOptions.SAVECHANGES);
    }

  6. #6
    Join Date
    Mar 2003
    Location
    Byckeye, AZ
    Posts
    804
    So, the script works and there is a UI with a button to run the script. The next thing I need to do is either select a folder and run the process on each item in the folder, or tell it to loop the script until there are no open files (so that I can just open a bunch of files at a time and run the script once and have it execute on each open file).

    To create a loop, it looks like a need a condition in the code (something like telling it to continue doing the loop as long as there is an open file or something). Anyone know if there is a list of conditions specific to Photoshop that I could reference?

  7. #7
    Join Date
    Jan 2007
    Posts
    640
    Here's how I did my file folder scanning. This may/may not be applicable as there's some specific code that uses other functions in my script. It should give you a basic idea though.

    Code:
    function scanSubFolders(tFolder, mask) { // folder object, RegExp or string
        var sFolders = new Array();
        var allFiles = new Array();
        sFolders[0] = tFolder;
        for (var j = 0; j < sFolders.length; j++){ // loop through folders            
            var procFiles = sFolders[j].getFiles();
            for (var i=0;i<procFiles.length;i++){ // loop through this folder contents
                if (procFiles[i] instanceof File ){
                    if(mask==undefined) allFiles.push(procFiles[i]);// if no search mask collect all files
                    if (procFiles[i].fullName.search(mask) != -1) allFiles.push(procFiles[i]); // otherwise only those that match mask
            }else if (procFiles[i] instanceof Folder){
                sFolders.push(procFiles[i]);// store the subfolder
                scanSubFolders(procFiles[i], mask);// search the subfolder
             }
          }
       }
       return [allFiles,sFolders];
    };
    
    function main() {
        var fileFilter = "PSD Files:*.psd,PNG Files:*.png,JPEG:*.jpg;*.jpeg;*.jp2";
        var wmFileName = File.openDialog ("Please seledct watermakr file.", fileFilter, false);
        
        var srcFolder = Folder.selectDialog ("Please select source folder");
        var dstFolder = Folder.selectDialog ("Please choose ouput folder");
        var fileandfolderAr = scanSubFolders(srcFolder,/\.(jpg|tif|bmp|gif|png|)$/i);    
        var fileList = fileandfolderAr[0];
            
        open(new File(wmFileName));
        var wmDoc = app.documents.getByName(wmFileName.name);
    
        for(var i = 0; i < fileList.length; i++)  {
            var picFile = new File(fileList[i]);
            // $.writeln(picFile.name);
            var picDoc = open(picFile);        
            picDoc.changeMode (ChangeMode.RGB);
            picDoc.bitsPerChannel = BitsPerChannelType.EIGHT;
            app.activeDocument  = wmDoc;
            wmDoc.activeLayer.duplicate(picDoc);
            app.activeDocument = picDoc;
            picDoc.activeLayer = picDoc.layers.getByName("Background copy");
            var layer = picDoc.activeLayer;
            layer.name = "Watermark";
            ResizeWaterMark ();        
            MoveToBottomLeft(0,0);
            
            var oldColor = GetColor (picDoc, 5, picDoc.height-5);                
            layer.opacity = 37;
            layer.blendMode = BlendMode.MULTIPLY;
            var fiftyGrey = new SolidColor();
            fiftyGrey.rgb.red = 128;
            fiftyGrey.rgb.green = 128;
            fiftyGrey.rgb.blue = 128;
            if(oldColor.rgb.red <= fiftyGrey.rgb.red)
                if(oldColor.rgb.green <= fiftyGrey.rgb.green)
                    if(oldColor.rgb.blue <= fiftyGrey.rgb.blue)                
                        layer.blendMode = BlendMode.DIFFERENCE;
                
                var saveFileName = picFile.name.substr (0, picFile.name.lastIndexOf('.'));
                var saveFile = new File(dstFolder.fullName + "/wm" + saveFileName + ".jpg");
                // $.writeln(saveFile.fullName);    
                SaveForWeb (saveFile, 70);
                picDoc.close(SaveOptions.DONOTSAVECHANGES);
        };  
        wmDoc.close(SaveOptions.DONOTSAVECHANGES);
    };
    
    main();

  8. #8
    Join Date
    Mar 2003
    Location
    Byckeye, AZ
    Posts
    804
    awesome... thanks. I'll dig through that and see what I can learn.

  9. #9
    Join Date
    Aug 2014
    Location
    Samarinda
    Posts
    2
    I was just learning about the script, perhaps the explanation above existing members who help you
    Properti terkini memberikan berita perralatan rumah tangga interior hunian dan desain gambar rumah minimalis terbaik sepanjang masa.

  10. #10
    Join Date
    Jan 2015
    Posts
    1
    To create a loop, it looks like a need a condition in the code (something like telling it to continue doing the loop as long as there is an open file or something). Anyone know if there is a list of conditions specific to Photoshop that I could reference?
    Arslan1!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •