Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all 12244 articles
Browse latest View live

batch odd dimension images to square

$
0
0

Hi

 

I have lots of images that are all different sizes and more coming.

 

I need to create an action that makes these images square in px dimensions, with the new side dim. the dim. of the longest side.

 

I need to add canvas (light gray) to the short side.

 

I understand actions but not scripting.

 

Thanks exceedingly.


How can get and set x , y position of opend image ?

$
0
0

Hi,

 

I used photoshop scripting in back end.

I  am using javascript.

 

Here i do following step for image adding in layer.

1. Create main window for save psd file.

2. Create new layer in this window i.e. layer1.
3. Open image in separate new window.
4. Copy image from this window.
5. Set focus (back) in main window and i layer1.
6. Past image here.

 

Here my image is always set on center of layer1.
And i want to set image in given x,y position in layer1

 

Is any one help me so i can set this pasted image in given x,y position in layer1 ?

 

Thanks,
Mohit.

Retriving different histograms from activeDocument

$
0
0

Hi

 

In CS4 & CS5 on the histogram menu it's possible to select different  types of histograms

from the channel drop box.

 

I can select RGB, R,G,B, Colors and luminosity.

However when I execute a DoJavaScipt on the active document I can only get

the luminosity or specific R, G, B histograms based on the activeChannels  container.

 

How can I get the RGB or Colors histogram (I know I can sum up all the  different channels (R,G,B)

but it seems stupid since the RGB data and color is already presented.

 

Do I need to write a plug-in to extract this data for me?

 

Thanks

Scripting Lens Correction to process millions of photos

$
0
0

We have several million "Fish-Eye" images that we need to flatten out and the new "Lens Correction" feature of Photoshop CS5 appears to work pretty well.  I was able to use the predefined File -> Automate -> Lens Correction function to process a hanfull of images and it worked fine for a small batch.

 

I would like to know if there is a way with Photoshop CS5 to script/batch out a process so that I can use it to process the millions of individual files we need to have processed.

 

Also, I am not familiar with the Photoshop "Batch" or "Scripting" process, so assuming the above request is possible, some direction on how to proceed would be greatly appreciated.

 

Thank You.
Lee

Watch Folder

$
0
0

Hello,

 

Is there a way to have Photoshop watch a folder for new images and run some actions on the newly added files - after which removing the original from that folder.

 

I need to automate the follwoing:

Image is added to watch folder

Photoshop

  1. Detects new image
  2. Opens image
  3. Runs actions
  4. Saves to a new directory

File is deleted from watch folder.

 

I am on Mac 10.7 and have Automator at my disposal. I'm also familiar with scripting but not specifically for Photoshop so I prefer scripting would be the last resort.

 

Any help or guidance is greatly appreciated.

 

Thank you!

 

V

A script for "Save for Web" as .jpg

$
0
0

I found a script that saves the current selected document in Photoshop as .png to the Desktop, and use it all the time.

 

function main() {

          // declare local variables

          var doc = app.activeDocument;

          var docName = app.activeDocument.name.slice(0,-4);

 

 

    var saveFile = new File("~/Desktop/" + docName + ".png");

    pngSaveOptions = new PNGSaveOptions();

    pngSaveOptions.interlaced = false;

    doc.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);

}

 

main();

 

 

Now I'd really like a similar script to do "Save for Web" as .jpg files, without a colour profile, to the Desktop. Preferably a version to save as 100% quality and one to save as 60% quality.

Any help would be greatly appreciated.

Weird layer-renaming issue.

$
0
0

On Win7, PS 19.0 I am encountering a strange issue with renaming layers.

 

It boils down to these steps:

  1. start a fresh PS
  2. Rename a layer manually works just fine.
  3. Run a layer-making script
  4. Now, renaming layers manually is nearly impossible: you double-click the desired layer to enable editable layer name text, but only have 1 second to type in the entire input before it automatically sets.

 

What's worse, after this the layer issue persists even in new documents, all the way until app restart.

 

This is my layer-making script:

 

#target photoshop

function test(){

  var doc = app.activeDocument;

  var arr = [

    "Name 1",

    "Name 2"

  ];

  var newLayer;

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

    newLayer = doc.artLayers.add();

    newLayer.name = arr[i];

  };

};

test();

 

Has anyone come across this?

Ghost Mannequin scripted

$
0
0

Hey guys, I was reading a lot about scripting the wand or quick selection. But still didn't managed to create something that will work on my case.

I would need a script that deletes the mannequin and leave only the apparel on a clean white background. (see the pictures attached)

 

NBMSTSL-NV-1.jpg

NBMSTSL-NV-3.jpg


Script for making random thumbnails from single image

$
0
0

Hi all,

 

I need something like a hundred different thumbnails from each image in a series of images, that is, hundred random sections of the same image, saved in a folder as jpg,  and i was hoping that i could find a script for this.

 

What the script has to do is:

 

  1. select the size of the crop (this would also be the dimensions of the thumbnail saved)
  2. rotate crop selection in a random orientation and place the crop randomly on the canvas
  3. save the image as a jpg in a folder
  4. return to original image,
  5. repeat process x times before quitting script.

 

I dont think this should be to difficult to make a script for, but unfortunately i don´t know how to code.

 

Is there anybody that could help me with this?

 

This would save me a lot of time!

Optimize to file size in save for web and devices

$
0
0

Hi,

 

I save multiples files everyday to use on the website, i would like to save it in specified size like 45kb, 75kb, 100kb etc.. using save for web and devices helps me alot. But is there any way to get it automated? any leads would be highly appreciated.

Script to Create Folders Using Photoshop Scripting Mac/Windows

$
0
0

Can anyone help me. I want to create a script to create folders and run the script in Photoshop.

 

I am a real novice at scripting and I do not know if this can be done.

 

Thanks

Using mouse wheel to zoom and pan

$
0
0
I was wondering if there would be a way to make a javascript that would load at Photoshop's startup that would allow the user to zoom in and out using the mouse wheel (instead of using it for scrolling), and to use that same mouse wheel as a third button (when you push on the mouse wheel) or any third button on a three button mouse to pan in your image. I'm a 3ds max user and I love the way the navigation work in that software so it'd be great to be able to do that for Photoshop and Illustrator and get rid of those useless key shortcuts that we need to use to zoom and pan.

For the pan fonction, I guess if there was a way to simply say "when the third mouse button is pressed, press the space button, until the mouse button is released" it could work. But then it would force the panning to stop when the mouse goes offscreen, unlike in 3ds max where you can pan for whatever distance you want, even if you have the loop throught the screen ten times.

For the zoom function, if scolling up could simply "push" the keyboard shortcuts to zoom in/ zoom out it could work, but I don't know if that's possible. And then we'd have to disable the scrolling up and down in the document.

Anyways, if anyone has any ideas about that let me know! I've been looking for that for such a long time!

Did CC 2014.2 break textItem.size?

$
0
0

Scripts that worked before the update are now broken, and text layers created via script are all 12px. See this simple script:

 

var docRef = activeDocument;
var TextLabel = docRef.artLayers.add();
TextLabel.kind = LayerKind.TEXT;
TextLabel.name = "Test";
TextLabel.textItem.contents = "This text should be 50pt";
TextLabel.textItem.size = new UnitValue("50 points"); // other variations, such as TextLabel.textItem.size = 50 also fail.
TextLabel.textItem.font = "Monaco";

 

Any help? Thanks.

Help needed to enhance Image Processor Pro Script to save transparency in TIF

$
0
0

Hi everyone,

 

this is my first post in this community.

 

We have a droplet which reduces the resolution of tif images to 72dpi and save the tif image with transparency. This works fine, but it took to long for the whole process of many picture in different folders. That's the reason why we searched for another script which can preserve the folder structure and set the resolution of every tif image to 72dpi.

 

We found Image Processor Pro, which does exactly what we needed. The script works perfectly in CS5 and CS5.5 as it saves the tif with the transparency. Those saved tif images could be used in InDesign with the transparency.

 

BUT Image Processor Pro script works not so perfectly in CS6 as it seems that this option to save a tif with transparency is not implemented or does not work in the script. The result is that those converted tif images are w/o transparency in InDesign. That's a huge problem for us.

 

 

This is the point where I need your help. Neither I have experience yet with jsx-files nor with the right syntax of it.

 

Is there a way for anybody of you to implement / enhance Image Processor Pro so it will save tif with transparency?

 

We used the latest German Version of Image Processor Pro: 2.3.1 (link: http://www.russellbrown.com/scripts.html)

 

(The German version contains only german on screen texts!)

 

I am very thankful for every help you can give.

 

Thanks in advance for your help.

Layer Comps to JPG Save for Web

$
0
0

Hello everyone,

 

I'm using the "Layer comp to files" script a lot to send some designs to clients. And sometimes I need to send a lot of JPGs at once, wich are created with "Layer comps to files", but they are all around 300k or more, and when I use Safe for web it reduces the file size a lot! But I don't want todo it all manually again offcourse.

 

So I was wondering, is there any script what saves your Layer Comps JPGs to a JPG what is compressed with the Save for Web technology?

 

Thanks in advance.

 

 

Jeroen


Debounce w/o setTimeout()?

$
0
0

Hi,

I'm looking for a way to implement a Debounce function (see here), like this one:

 

// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {  var timeout;  return function() {  var context = this, args = arguments;  var later = function() {  timeout = null;  if (!immediate) func.apply(context, args);  };  var callNow = immediate && !timeout;  clearTimeout(timeout);  timeout = setTimeout(later, wait);  if (callNow) func.apply(context, args);  };
};

 

To be used in ScriptUI.

Problem is that we don't have setTimeout in ExtendScript land, and $.sleep is blocking / not cancelable.

There is a working implementation for InDesign, using app.idleTasks, which, again, we don't have in Photoshop so back to square one.

Suggestions?

 

Thank you!

 

Davide Barranca

Photoshop Script to Save File One Folder up and in Another.

$
0
0

Hiya,

I'm working on piecing together a script for Photoshop that will take my current open photo (high res .psd) and duplicate it (without 'copy' being appended) - which I have done... and I have it currently able to save the .jpg in the folder next to the source .psd I've been working on.

 

What I'd really like is for the script to be able to look at the path where the .psd is, go up the tree one, then into the "web" folder and save the .jpg there.

 

example folder structure for each session:

folders.jpg

 

so while working the .psd I want to assign an action with F key to run the script... and then the script will duplicate the document and save is in the "02 - web" folder.

 

Currently I have it working, but only to save next to the original .psd and here's the code I have (modified from pieces of script found around the web)

 

 

//Duplicate doc

var doc = app.activeDocument

var fname = doc.name.split(".")

var fname = fname[0]

var newDoc = doc.duplicate(fname)

 

//save the jpg

if (app.documents.length > 0) {

  var thedoc = app.activeDocument;

  var docName = thedoc.name;

  if (docName.indexOf(".") != -1) {

    var basename = docName.match(/(.*)\.[^\.]+$/)[1];

  } else {

    var basename = docName;

  }

  //getting the location, if unsaved save to desktop;

  try {

    var docPath = doc.path;

  } catch (e) {

    var docPath = "~/Desktop";

  }

  var jpegOptions = new JPEGSaveOptions();

  jpegOptions.quality = 10;

  jpegOptions.embedColorProfile = true;

  jpegOptions.matte = MatteType.NONE;

  var filename = docPath + '/' + basename + '.jpg';

  thedoc.saveAs((new File(filename)), jpegOptions, true);

};

 

 

any help with how to get it to go up the tree and into that folder would be greatly appreciated.

 

Then after that, phase 2 would be to see if I could get it to use the "JpegMini Pro" plugin to save the .jpg - or at least "save for web" and not the straight "save as" - but jpegmini pro is preferred (that one might be hard, I don't know)

 

Batch Processing with Multiple Actions

$
0
0

Hello all,

Using the Scripts Events Manager I run a set of seven actions during the file open event to a each file.

The  next steps to apply these seven actions to a folder of images.

 

What are the Photoshop options available to apply this set of seven actions to a folder of  images? 

 

Screen Shot 2014-05-15 at 9.24.38 AM.png

Histogram passed and drawn into a Layer. Done!

$
0
0

Hi, I have made an exercise that can be usefull to someone.

On a active image, it builds and draws the histograms on several layers.

This works only on RGB images and if they have more than 8bits/channel, it will reduce to 8bit/channel before proced.

 

I used this on windows 10 and CC(2017)

 

Enjoy or complete and develop it as you want.

 

This next code will build 4 layers

1 -  the 3 rgb channels coloured histogram

2 - the Max([R], [G], [B]) Luminosity RGB histogram (gets the max value of each channel)

3 - the 8bit Lightness channelLab histogram (the image will be reverted again to RGB afterwards)

4 - 8bit Luminosity RGB histogram

 

 

addHistogram(true); // this draws a layer with a coloured 8bit RGB histogram
addHistogram(false, false, true); //  this draws the Max([R], [G], [B]) Luminosity RGB histogram (gets the max value of each channel)
addHistogram(false, true); // this draws a layer with 8bit Lightness channel Lab histogram
addHistogram(false, false); // this draws a layer with 8bit Luminosity RGB histogram


///////////////////////////////  HISTOGRAM IN LAYER   ///////////////////////////////////
function addHistogram(RGB, Lab, MaxRGB) {    ///////////////////////////////////////////////// createProgressWindow    var createProgressWindow = function(title, message, hasCancelButton) {      var win;      if (title == null) title = "Work in progress";      if (message == null) message = "Please wait...";      if (hasCancelButton == null) hasCancelButton = false;      win = new Window("palette", "" + title, undefined);      win.bar = win.add("progressbar", {x: 20, y: 12, width: 300, height: 20 }, 0, 100);      win.stMessage = win.add("statictext", { x: 10, y: 36, width: 320, height: 20 }, "" + message);      win.stMessage.justify = 'center';       if (hasCancelButton) {        win.cancelButton = win.add('button', undefined, 'Cancel');        win.cancelButton.onClick = function() {          win.close();          throw new Error('User canceled the pre-processing!');        };      }      this.reset = function(message) {        win.bar.value = 0;        win.stMessage.text = message;        return win.update();      };      this.updateProgress = function(perc, message) {        if (perc != null) win.bar.value = perc;        if (message != null) win.stMessage.text = message;        return win.update();      };      this.close = function() {        return win.close();      };      win.center(win.parent);      return win.show();    };    //    // the other layer histograms, if exist, should be invisible so the reading is only on the pixels of the image itself    if (getLayer("RGB histogram")) activeDocument.artLayers.getByName ("RGB histogram").visible = false;    if (getLayer("Lightness Lab histogram")) activeDocument.artLayers.getByName ("Lightness Lab histogram").visible = false;    if (getLayer("Luminosity RGB")) activeDocument.artLayers.getByName ("Luminosity RGB").visible = false;    if (getLayer("Luminosity Max[R][G][B]")) activeDocument.artLayers.getByName ("Luminosity Max[R][G][B]").visible = false;    //    var layerName = (RGB) ? "RGB histogram" : ((Lab) ? "Lightness Lab histogram" : ((MaxRGB) ? "Luminosity Max[R][G][B]" : "Luminosity RGB"));     //    if (!getLayer(layerName)) {        // it works only on RGB images        if (activeDocument.mode == DocumentMode.RGB) {            // if the image is 16bit/channel or more it sets 8bits/channel before read the histogram            if (!activeDocument.bitsPerChannel == BitsPerChannelType.EIGHT) activeDocument.bitsPerChannel = BitsPerChannelType.EIGHT;            $.writeln(layerName);            var wasHereLayer = activeDocument.activeLayer;            var unitsAntes = app.preferences.rulerUnits;            var foregroundPreviousColor = app.foregroundColor;            app.preferences.rulerUnits = Units.PIXELS; // importante            activeDocument.quickMaskMode = false;            activeDocument.selection.deselect();            //            // read histogram:            var hL = activeDocument.histogram;            var hR = activeDocument.channels["Red"].histogram;            var hG = activeDocument.channels["Green"].histogram;            var hB = activeDocument.channels["Blue"].histogram;            // if you want the Luminosity of Lab, export it to Lab, read it, and revert it to RGB            if (Lab) {                activeDocument.changeMode (ChangeMode.LAB);                // read Lightness channel histogram of Lab                var hL = activeDocument.channels["Lightness"].histogram;                // revert to RGB                activeDocument.changeMode (ChangeMode.RGB);            } else {                // read Luminosity composite channel histogram of RGB                var hL = activeDocument.histogram;            }            //            var ww = activeDocument.width.as('px');            var hh = activeDocument.height.as('px');            var totalPixels = ww*hh;            var totalPixels1Col = totalPixels/256;            //            var pBar = new createProgressWindow("Histogram building...", "Please wait", false);            //            activeDocument.artLayers.add();            activeDocument.activeLayer.name = layerName;            activeDocument.activeLayer.move( activeDocument, ElementPlacement.PLACEATBEGINNING );            activeDocument.activeLayer.blendMode = BlendMode.NORMAL; // blending mode "normal"            activeDocument.activeLayer.opacity = 60; // opacity 60%            //            var hhGraph = 60;            var hY = 400; // base y of graph            var hX = 100; // base x of graph            // base transparent            app.foregroundColor.rgb.red = 0;            app.foregroundColor.rgb.green = 0;            app.foregroundColor.rgb.blue = 0;            //            drawSelectionScreen (hX-2, hY+2, 258+hX, hY-322);            // fill (filltype [, mode] [, opacity] [, preserveTransparency])  // filltype: SolidColor  |  mode: ColorBlendMode  |  opacity: [1..100]            app.activeDocument.selection.fill(app.foregroundColor, ColorBlendMode.SCREEN, 40, false);            activeDocument.selection.deselect();            //            var myHist = [];            //            if (RGB) {                for (var a in activeDocument.componentChannels) {                    //  criar as 3 cores R, G e B e o graph da cada uma                    (a==0) ? app.foregroundColor.rgb.red = 255 : app.foregroundColor.rgb.red = 0;                    (a==1) ? app.foregroundColor.rgb.green = 255 : app.foregroundColor.rgb.green = 0;                    (a==2) ? app.foregroundColor.rgb.blue = 255 : app.foregroundColor.rgb.blue = 0;                    //                    if (a==0) myHist = hR;                    if (a==1) myHist = hG;                    if (a==2) myHist = hB;                    //                    for ( i = 0; i <= 255; i++ ) {                        var col = i+hX;                        var YYY = Math.min(Math.floor(myHist[i]*hhGraph/totalPixels1Col), 320);                        drawSelectionScreen (col, hY, col+1, hY-YYY);                        //                        var percent = Math.floor(((i+1)+(a*256))*100/768);                        pBar.updateProgress (percent, activeDocument.componentChannels[a].name.toUpperCase() + " Channel " + percent+ " % completed");                    }                    // fill (filltype [, mode] [, opacity] [, preserveTransparency])  // filltype: SolidColor  |  mode: ColorBlendMode  |  opacity: [1..100]                    app.activeDocument.selection.fill(app.foregroundColor, ColorBlendMode.SCREEN, 100, false);                    activeDocument.selection.deselect();                }            } else {                app.foregroundColor.rgb.red = 255;                app.foregroundColor.rgb.green = 255;                app.foregroundColor.rgb.blue = 255;                myHist = hL;                for ( i = 0; i <= 255; i++ ) {                    var col = i+hX;                    if (MaxRGB) {                        var YYY = Math.min(Math.floor(Math.max(hR[i], hG[i], hB[i])*hhGraph/totalPixels1Col), 320);                    } else {                        var YYY = Math.min(Math.floor(myHist[i]*hhGraph/totalPixels1Col), 320);                    }                    drawSelectionScreen (col, hY, col+1, hY-YYY);                    //                    var percent = Math.floor((i+1)*100/256);                    pBar.updateProgress (percent, "Luminosity Channel " + percent+ " % completed");                }                // fill (filltype [, mode] [, opacity] [, preserveTransparency])  // filltype: SolidColor  |  mode: ColorBlendMode  |  opacity: [1..100]                app.activeDocument.selection.fill(app.foregroundColor, ColorBlendMode.SCREEN, 100, false);                activeDocument.selection.deselect();            }            pBar.close();            // activeDocument.activeLayer = wasHereLayer;            app.preferences.rulerUnits = unitsAntes;            app.foregroundColor = foregroundPreviousColor;            $.gc();        } else {            alert("Must be an RGB image");        }    } else {        alert("Already has created this '" + layerName + "' layer!");        return;    }    function drawSelectionScreen(x1, y1, x2, y2) {        $.level = 0;        try {            // SelectionType.SELECTEDAREA | DIMINISH | EXTEND | INTERSECT | REPLACE            activeDocument.selection.select([[ x1, y1], [x2, y1], [x2, y2], [x1,y2]], SelectionType.EXTEND, 0, false);        } catch(e) {}        $.level = 1;    }    function drawLineScreen(x1, y1, x2, y2, width, transparency) {        $.level = 0;        try {            var desc = new ActionDescriptor();            var lineDesc = new ActionDescriptor();            var startDesc = new ActionDescriptor();            startDesc.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), x1 );            startDesc.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), y1 );            lineDesc.putObject( charIDToTypeID('Strt'), charIDToTypeID('Pnt '), startDesc );            var endDesc = new ActionDescriptor();            endDesc.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), x2 );            endDesc.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), y2 );            lineDesc.putObject( charIDToTypeID('End '), charIDToTypeID('Pnt '), endDesc );            lineDesc.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Pxl'), width ); //            desc.putObject( charIDToTypeID('Shp '), charIDToTypeID('Ln  '), lineDesc );            desc.putEnumerated( charIDToTypeID( "Md  " ), charIDToTypeID( "BlnM" ), charIDToTypeID( "Scrn" ) ); // mode: Screen            desc.putUnitDouble( charIDToTypeID( "Opct" ), charIDToTypeID( "#Prc" ), transparency ); // [0-100] transparency            desc.putBoolean( charIDToTypeID('AntA'), false ); // important antialias should be false            executeAction( charIDToTypeID('Draw'), desc, DialogModes.NO );        } catch(e) {}        $.level = 1;    }    //////////////////////////////////    function getLayer(layername) {        var result = false;        for (var a=0; a<activeDocument.artLayers.length ; a++) {            if (String(activeDocument.artLayers[a].name) == layername) {                result = true;                break;            }        }        return result;    }
}

Searching Arrays - indexOf

$
0
0

I was trying to search an array, and on the web it says to use something like this:

 

var tA = ['one','two'];

$.writeln(tA.indexOf ('one'))

 

However, when I try this, I get: tA.indexOf is not a function."  It works with a string variable but not an array.  Is this a bug, or an I doing something wrong?

Viewing all 12244 articles
Browse latest View live


Latest Images